user306080
user306080

Reputation: 1527

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?

Upvotes: 0

Views: 2071

Answers (1)

Ivan Valadares
Ivan Valadares

Reputation: 949

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

Upvotes: 1

Related Questions