ASP.NET Core does not start up when static file path does not exist

So by default ASP.NET Core only serves static files from wwwroot. Since I’m sold by architecture in vertical slices, I like to have feature folders.

This means I will put the controller, model, view and any static files in a single feature folder. To expose these static files, I just configure:

public void Configure(...)
{
...
  app.UseStaticFiles(new StaticFileOptions
  {
    FileProvider = new PhyiscalPhileProvider(
      Path.Combine(Directory.GetCurrentDirectory(), 
        @"Features\MyFeature\www)),
      Request.Path = new PathString("/MyFeature")
  });
...
}

Now, if the “Features\MyFeature\www” part is an invalid path, you will get a clear exception when you are debugging. Typically however, the static files will be file types that are not included in the build output by default (e.g. js)

So on your machine while you are developing everything is fine. But when you publish, the static files are not included, which results in an empty directory which is then not  included, which ends with the web application not starting up!

In my case, this was on an Azure App Service, which showed a nice custom error page without any clue. Took me some troubleshooting to get the logs that pointed me to the root cause.

Ah well, TheMoreYouKnow.

Theme music for this blog post

Advertisements
ASP.NET Core does not start up when static file path does not exist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s