How to achieve same behavior in ASP.NET MVC5 with static files like it works on aspnet-core with app.UseDefaultFiles(); app.UseStaticFiles();
?
I mean serving static files from some folder over root, e.g. /wwwroot/some.html
must be opened on mysite.com/some.html
, /wwwroot/img/test.jpg
on mysite.com/img/test.jpg
etc.
Update: I have created wwwroot
folder and added following rule to web.config
:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Static" stopProcessing="true">
<match url="^(?!(wwwroot/|api/))(.*)$" ignoreCase="true"></match>
<action type="Rewrite" url="/wwwroot/{R:1}" />
</rule>
</rules>
So IIS must return files from wwwroot
except when calls go to /api/something
, but I'm always getting index.html
in wwwroot
folder and never other files. Api's URL works good.
What I'm doing wrong?
All works in that way:
Don't forget to install rewrite module.