简体   繁体   中英

Routing Static Files in ASP.NET Core

Good day everyone.

I have tried several to make static files working through routing but is does not seem to work in IIS.

My current approach is this:

app.MapWhen(context =>
{
    var path = context.Request.Path.Value;
    return path.StartsWith("/Images", StringComparison.OrdinalIgnoreCase);
}, config => config.UseStaticFiles());

Any clues what should I do in order make static files routing working?

Here is an example how you can access static Files in a folder named "Content" in the project Root.

app.UseStaticFiles(new StaticFileOptions
{
      FileProvider = new PhysicalFileProvider(
      Path.Combine(Directory.GetCurrentDirectory(), "Content")),
      RequestPath = "/Content"
});

ex: http://localhost/content/myfile.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM