c# - 允许用户进行表单例份验证在 Azure 网站中不起作用

标签 c# asp.net azure forms-authentication azure-web-app-service

我在 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/

相关文章:

c# DataGridView 从行/列获取内容

C# 开启枚举

.net - 更新 Excel 文件中的小计

使用 Angular 的 .NET Core 2.1 应用程序出现 Azure 应用服务 502.5 错误

Azure DevOps - 我的自定义版本计数器变量存储在哪里?

c# - 这是什么系统颜色?

c# - 应用程序未等待完成任务

c# - Visual Studio 2015 构建需要很长时间

javascript - asp.net 中的 ValidationExpression 验证数字和字符(/和 -)

azure - 发布 azure 函数时找不到名称错误的应用程序