What is the easiest way to serve static files using ASP.NET 5?

I am trying to create the simplest possible ASP.NET 5 project to serve static files, regardless of the Visual Studio project templates. However, when I request a file, I get an empty response. Here is my code:

project.json:

{ "wwwroot": "wwwroot", "dependencies": { "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8", "Microsoft.AspNet.StaticFiles": "1.0.0-beta8" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" }, "frameworks": { "dnx46": { } } } 

Startup.cs:

 using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; namespace Study.StaticFileServer { public class Startup { public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); } } } 

Finally, there is a folder called "wwwroot" containing "downloadme.txt".

When I run dnx web and request a file, the answer is empty. What should I add to make this work?

+6
source share
2 answers

It was hard to notice, but there is an error in project.json . Change wwwroot to webroot

Current:

 { "wwwroot": "wwwroot", [...] 

Must be:

 { "webroot": "wwwroot", [...] 

webroot points to the root of the application from which static files are made.

+3
source

I think you would do it, but repeat it.

  • When you run "dnx web" on the command line. The following output should be shown

  • Use " http: // localhost: 5000 " in any browser, initially you will see a blank screen. Then find the file in the wwwroot folder as shown below Read file in browser

0
source

All Articles