我在 Azure 上有一个网站 - example.azurewebsites.net。 我将默认页面配置为index.html。 现在,网站应该拒绝未经身份验证的用户访问网站,除了index.html和login.html。
这是我的代码:
<system.webServer>
<defaultDocument>
<files>
<clear/>
<add value="index.html" />
</files>
</defaultDocument>
</system.webServer>
<location path="index.html">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<authentication mode="Forms">
<forms loginUrl="login.html" defaultUrl="~/" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
example.azurewebsites.net/index.html - 这有效。 example.azurewebsites.net - 但这不是(重定向到login.html)。 但它们应该是相同的。 没有身份验证 example.azurewebsites.net 重定向到 index.html 没有问题。
我哪里错了?
最佳答案
您可能希望检查的一件事是您的 web.config 中是否存在以下内容。
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthenticationModule" />
<add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule" />
</modules>
您通常不需要执行此操作,因为该模块是在本地操作系统上的 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config 中定义的。然而,在 Azure Web 服务环境中情况并非如此。
关于c# - 允许用户进行表单例份验证在 Azure 网站中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42285283/