-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File Providers topic update for 3.0 (#14027)
- Loading branch information
Showing
24 changed files
with
458 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
...s/file-providers/samples/2.x/FileProviderSample/Pages/Shared/_CookieConsentPartial.cshtml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
...le-providers/samples/2.x/FileProviderSample/Pages/Shared/_ValidationScriptsPartial.cshtml
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
aspnetcore/fundamentals/file-providers/samples/2.x/WatchConsole/quotes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"As developers, we fail in two ways: We build the thing wrong, or we build the wrong thing." - Steve Smith | ||
|
||
"That's not a thing ... You just made that up." - David Fowler | ||
"That's not a thing ... You just made that up." - David Fowler |
16 changes: 16 additions & 0 deletions
16
...core/fundamentals/file-providers/samples/3.x/FileProviderSample/FileProviderSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.0.0-preview8.19405.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="Resource.txt" /> | ||
</ItemGroup> | ||
|
||
</Project> |
26 changes: 26 additions & 0 deletions
26
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/Error.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@page | ||
@model ErrorModel | ||
@{ | ||
ViewData["Title"] = "Error"; | ||
} | ||
|
||
<h1 class="text-danger">Error.</h1> | ||
<h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
||
@if (Model.ShowRequestId) | ||
{ | ||
<p> | ||
<strong>Request ID:</strong> <code>@Model.RequestId</code> | ||
</p> | ||
} | ||
|
||
<h3>Development Mode</h3> | ||
<p> | ||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred. | ||
</p> | ||
<p> | ||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong> | ||
It can result in displaying sensitive information from exceptions to end users. | ||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> | ||
and restarting the app. | ||
</p> |
19 changes: 19 additions & 0 deletions
19
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/Error.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace FileProviderSample.Pages | ||
{ | ||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
public class ErrorModel : PageModel | ||
{ | ||
public string RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
|
||
public void OnGet() | ||
{ | ||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@page | ||
@model IndexModel | ||
@{ | ||
ViewData["Title"] = "File Provider Sample"; | ||
} | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
|
||
<div class="row"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h2 class="panel-title">Folder Contents</h2> | ||
</div> | ||
<div class="panel-body"> | ||
<ul> | ||
@foreach (var item in Model.DirectoryContents) | ||
{ | ||
if (item.IsDirectory) | ||
{ | ||
<li><strong>@item.Name</strong> folder</li> | ||
} | ||
else | ||
{ | ||
<li>@item.Name - @item.Length bytes</li> | ||
} | ||
} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/Index.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.FileProviders; | ||
|
||
namespace FileProviderSample.Pages | ||
{ | ||
public class IndexModel : PageModel | ||
{ | ||
private readonly IFileProvider _fileProvider; | ||
|
||
public IndexModel(IFileProvider fileProvider) | ||
{ | ||
_fileProvider = fileProvider; | ||
} | ||
|
||
public IDirectoryContents DirectoryContents { get; private set; } | ||
|
||
public void OnGet() | ||
{ | ||
DirectoryContents = _fileProvider.GetDirectoryContents(string.Empty); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...re/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/Shared/_Layout.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>@ViewData["Title"]</title> | ||
<style>body{margin:0;padding-bottom:20px;font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff;}h1{font-size:24px;margin:.67em 0;}pre{overflow:auto;}code,pre{font-family:monospace, monospace;font-size:1em;}button,input{margin:0;font:inherit;color:inherit;}button{overflow:visible;}button{text-transform:none;}input{line-height:normal;}{box-sizing:border-box;}:before,*:after{box-sizing:border-box;}input,button{font-family:inherit;font-size:inherit;line-height:inherit;}a{color:#337ab7;text-decoration:none;}h1,h2,h3,h4{font-family:inherit;font-weight:500;line-height:1.1;color:inherit;margin-top:20px;margin-bottom:10px;}h3{font-size:16px;}h4{font-size:18px;}p{margin:0 0 10px;}ol{margin-top:0;margin-bottom:10px;}code,pre{font-family:Menlo, Monaco, Consolas, "Courier New", monospace;}code{padding:2px 4px;font-size:90%;color:#c7254e;background-color:#f9f2f4;border-radius:4px;}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:1.42857143;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;-radius:4px;}pre code{padding:0;font-size:inherit;color:inherit;white-space:pre-wrap;background-color:transparent;border-radius:0;}.container{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto;}.container{width:800px;}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:normal;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;background-image:none;border:1px solid transparent;border-radius:4px;;color:#fff;background-color:green;border-color:gray;float:right}.panel{margin-bottom:20px;background-color:#fff;border:1px solid transparent;border-radius:4px;box-shadow:0 1px 1px rgba(0, 0, 0, .05);}.panel-body{padding:15px;}.panel-heading{padding:10px 15px;border-bottom:1px solid transparent;border-top-left-radius:3px;border-top-right-radius:3px;}.panel-title{margin-top:0;margin-bottom:0;font-size:16px;color:inherit;}.panel-default{border-color:#ddd;}.panel-default > .panel-heading{color:#333;background-color:#f5f5f5;border-color:#ddd;}.clearfix:before,.clearfix:after,.container:before,.container:after,.panel-body:before,.panel-body:after{display:table;content:" ";}.clearfix:after,.container:after,.panel-body:after{clear:both;}.body-content{padding-left:15px;padding-right:15px;}.panel-body{font-size:16px;}</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
@RenderBody() | ||
</div> | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
...core/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/_ViewImports.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@using FileProviderSample | ||
@namespace FileProviderSample.Pages | ||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
3 changes: 3 additions & 0 deletions
3
...etcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Pages/_ViewStart.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} |
20 changes: 20 additions & 0 deletions
20
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FileProviderSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ASP.NET Core File Provider Sample | ||
|
||
This sample illustrates the use of File Provider. This sample demonstrates the scenario described in the [File Providers in ASP.NET Core](https://docs.microsoft.com/aspnet/core/fundamentals/file-providers) topic. |
1 change: 1 addition & 0 deletions
1
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Resource.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
An embedded resource. |
54 changes: 54 additions & 0 deletions
54
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.FileProviders; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace FileProviderSample | ||
{ | ||
public class Startup | ||
{ | ||
private readonly IWebHostEnvironment _env; | ||
|
||
public Startup(IWebHostEnvironment env) | ||
{ | ||
_env = env; | ||
} | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddRazorPages(); | ||
|
||
#region snippet1 | ||
var physicalProvider = _env.ContentRootFileProvider; | ||
var manifestEmbeddedProvider = | ||
new ManifestEmbeddedFileProvider(Assembly.GetEntryAssembly()); | ||
var compositeProvider = | ||
new CompositeFileProvider(physicalProvider, manifestEmbeddedProvider); | ||
|
||
services.AddSingleton<IFileProvider>(compositeProvider); | ||
#endregion | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Error"); | ||
} | ||
|
||
app.UseStaticFiles(); | ||
app.UseRouting(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapRazorPages(); | ||
}); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...e/fundamentals/file-providers/samples/3.x/FileProviderSample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...re/fundamentals/file-providers/samples/3.x/FileProviderSample/appsettings.Production.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Error", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
aspnetcore/fundamentals/file-providers/samples/3.x/FileProviderSample/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
39 changes: 39 additions & 0 deletions
39
aspnetcore/fundamentals/file-providers/samples/3.x/WatchConsole/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.FileProviders; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace WatchConsole | ||
{ | ||
public class Program | ||
{ | ||
#region snippet1 | ||
private static PhysicalFileProvider _fileProvider = | ||
new PhysicalFileProvider(Directory.GetCurrentDirectory()); | ||
|
||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Monitoring quotes.txt for changes (Ctrl-c to quit)..."); | ||
|
||
while (true) | ||
{ | ||
MainAsync().GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
private static async Task MainAsync() | ||
{ | ||
IChangeToken token = _fileProvider.Watch("quotes.txt"); | ||
var tcs = new TaskCompletionSource<object>(); | ||
|
||
token.RegisterChangeCallback(state => | ||
((TaskCompletionSource<object>)state).TrySetResult(null), tcs); | ||
|
||
await tcs.Task.ConfigureAwait(false); | ||
|
||
Console.WriteLine("quotes.txt changed"); | ||
} | ||
#endregion | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
aspnetcore/fundamentals/file-providers/samples/3.x/WatchConsole/WatchConsole.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
3 changes: 3 additions & 0 deletions
3
aspnetcore/fundamentals/file-providers/samples/3.x/WatchConsole/quotes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"As developers, we fail in two ways: We build the thing wrong, or we build the wrong thing." - Steve Smith | ||
|
||
"That's not a thing ... You just made that up." - David Fowler |