I can't find many proper Core 1.0 tutorials yet, but when I google the method name, I get umpteen examples that say to include in Startup.cs
:
app.UseDefaultFiles();
app.UseStaticFiles();
Yet I get compile errors that neither method exists on app
, which is type IApplicationBuilder
. Are these calls no longer required, or named totally different, or set somewhere else?
UseStaticFiles() method adds StaticFiles middleware into the request pipeline. The UseStaticFiles is an extension method included in the StaticFiles middleware so that we can easily configure it. Now, open the browser and send http request http://localhost:<port>/default.html which will display default.
To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).
Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root.
In order to add the wwwroot folder, right-click on the project and then select add => new folder option and then provide the folder name as wwwroot.
in your project.json make sure you have a reference
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
in RC2 that will likely need to change to Microsoft.AspNetCore.StaticFiles
then you should be able to use
app.UseStaticFiles();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With