文件夹上的表单身份验证不起作用
Forms authentication on folder not working
我在 ASP.NET 中收到了一个 Web 项目。它包含一个 Content
文件夹和一个 index.html
文件。目前,人们可以去 mysite.com/content/index.html
。该项目中没有MVC控制器(我没有自己制作)。
我不希望人们直接进入 HTML 页面。我的站点根目录中有一个登录页面(所以 mysite.com
),所以如果用户未登录,我想将他们重定向到那里。我已经使用 Index 方法创建了自己的 HomeController。我已经设置了 ASP.NET 身份来授权对该方法的所有请求。我想设置表单身份验证以将所有未经授权的请求重定向到 Content 文件夹及其内容到 /Home/Index(或只是网站根 /)。
我在本网站和其他地方找到了几个非常相似的答案:
在网站根目录的 Web.config 中,我有以下代码:
<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>
但这不起作用,如果我转到 mysite.com/content/index.html
,我不会被重定向到 mysite.com
。我还尝试将它们拆分到不同的 web.config 文件中,如 this 答案中所述。我做错了什么?
不涉及静态内容的 mvc 管道 (html)。
将此行添加到项目 web.config 文件的 system.webServer 部分。
<modules runAllManagedModulesForAllRequests="true">
我在 ASP.NET 中收到了一个 Web 项目。它包含一个 Content
文件夹和一个 index.html
文件。目前,人们可以去 mysite.com/content/index.html
。该项目中没有MVC控制器(我没有自己制作)。
我不希望人们直接进入 HTML 页面。我的站点根目录中有一个登录页面(所以 mysite.com
),所以如果用户未登录,我想将他们重定向到那里。我已经使用 Index 方法创建了自己的 HomeController。我已经设置了 ASP.NET 身份来授权对该方法的所有请求。我想设置表单身份验证以将所有未经授权的请求重定向到 Content 文件夹及其内容到 /Home/Index(或只是网站根 /)。
我在本网站和其他地方找到了几个非常相似的答案: 在网站根目录的 Web.config 中,我有以下代码:
<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>
但这不起作用,如果我转到 mysite.com/content/index.html
,我不会被重定向到 mysite.com
。我还尝试将它们拆分到不同的 web.config 文件中,如 this 答案中所述。我做错了什么?
不涉及静态内容的 mvc 管道 (html)。
将此行添加到项目 web.config 文件的 system.webServer 部分。
<modules runAllManagedModulesForAllRequests="true">