I have been handed a web project in ASP.NET. It contains a Content
folder, with an index.html
file. At the moment, people can go to mysite.com/content/index.html
. There were no MVC controllers in this project (I didn't make it myself).
I don't want people going directly to the HTML page. I have a login page on the root of my site (so mysite.com
), so I want to redirect users there if they are not logged in. I've created my own HomeController with an Index method. I've set up ASP.NET Identity to Authorize all requests to that method. I want to set up forms authentication to redirect all unauthorized requests to the Content folder and its content to /Home/Index (or simply the website root /).
I've found several answers on this site and elsewhere that are pretty similar: In the Web.config of the website's root, I have this code:
<configuration>
<location path="~/Content">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<!-- some other nodes -->
<system.web>
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="/" />
</authentication>
</system.web>
</configuration>
But this doesn't work, if I go to mysite.com/content/index.html
I'm not redirected to mysite.com
. I also tried splitting these in different web.config files, as described in this answer. What am I doing wrong?
mvc pipeline not involving static contents (html).
add this line to system.webServer serction in projects web.config file.
<modules runAllManagedModulesForAllRequests="true">