Skip to content

Instantly share code, notes, and snippets.

@miroslavradojevic
Created February 12, 2018 10:05
Show Gist options
  • Save miroslavradojevic/befbc6a141f46296f8dd509946de9835 to your computer and use it in GitHub Desktop.
Save miroslavradojevic/befbc6a141f46296f8dd509946de9835 to your computer and use it in GitHub Desktop.
Add file server from relative path, named wwwroot.
class Startup {
public void Configuration(IAppBuilder app){
if (!Directory.Exists("wwwroot")) Directory.CreateDirectory("wwwroot");
var physicalFileSystem = new PhysicalFileSystem("./wwwroot");
// file server options
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem, // register file system
EnableDirectoryBrowsing = false
};
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
//app.Use<DefaultFileRewriterMiddleware>(physicalFileSystem); // middleware to direct non-existing file URLs to index.html
app.UseFileServer(options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment