Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the simplest way to serve static files using ASP.NET 5?

I'm trying to create the simplest possible ASP.NET 5 project to serve static files, without depending on Visual Studio project templates. However, when I request a file, I'm only receiving an empty response. Here's 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's a "wwwroot" folder containing "downloadme.txt".

When I run dnx web and request the file, the response is blank. What must I add to get this to work?

like image 755
Bryan Avatar asked Oct 29 '15 18:10

Bryan


1 Answers

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

Current:

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

Should be:

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

The webroot points to root of an application where static files are taken from.

like image 161
pg0xC Avatar answered Sep 28 '22 09:09

pg0xC