【问题标题】:ASP.NET web.config Forms Authentication, deny anonymous users, allow anonymous access for single filesASP.NET web.config 表单身份验证,拒绝匿名用户,允许匿名访问单个文件
【发布时间】:2015-12-05 13:35:06
【问题描述】:

我正在这里阅读本教程:http://blog.repsaj.nl/index.php/2007/08/mixing-forms-based-and-windows-authentication-in-aspnet/

这部分很有趣:

  1. 创建 3 个文件:Login.aspx、WebLogin.aspx、WinLogin.aspx。这些将是仅有的 3 个无需任何凭据即可访问的文件。您可以通过 Web.config 允许匿名访问,如下所示:

但是下面的部分是空白的:(

所以我的问题是,如何允许匿名访问我的 Login.aspx、WebLogin.aspx 和 WinLogin.aspx?

【问题讨论】:

  • @MrDywar,虽然您引用的问题与该问题的答案处理相同的 web.config 部分,但它与该问题不同,并且答案根本不相关。不过,我敢肯定,这可能是重复的。
  • @ps2goat 为什么?第一个链接 - 显示正确的授权语法,第二个 - 如何在多个文件上添加规则。
  • @MrDywar,对不起,它看起来像一个链接,我只点击了第二个。

标签: c# asp.net


【解决方案1】:

将此添加到您的 web.config。您需要为希望每个人都可以访问的每个页面重复此操作(在您的情况下为 3 个)。

    <location path="Login.aspx">
      <system.web>
        <authorization>
          <allow users="*" />
        </authorization>
      </system.web>
    </location>

【讨论】:

  • 您和其他已经提供的解决方案有什么区别?
  • 这是正确的吗? &lt;system.web&gt; &lt;authentication mode="Forms"&gt; &lt;forms loginUrl="~/Login"&gt;&lt;/forms&gt; &lt;/authentication&gt; &lt;authorization&gt; &lt;deny users="?" /&gt; &lt;/authorization&gt; &lt;compilation debug="true" targetFramework="4.5" /&gt; &lt;httpRuntime targetFramework="4.5" /&gt; &lt;/system.web&gt; &lt;location path="~/Login"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow users="*" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/location&gt;
  • 使用Login.aspx 而不是~/Login。其他一切看起来都很好。
【解决方案2】:
   <configuration>
  <system.web>

    <authentication mode="Forms">
      <forms loginUrl="SignIn.aspx" defaultUrl="Welcome.aspx"  protection="All">
        <credentials passwordFormat="Clear">
          <user name="lee" password="lee12345"/>
          <user name="add" password="add12345"/>
        </credentials>
      </forms>
    </authentication>

    <authorization>
      <deny users="?" />      <!--his will restrict anonymous user access-->
    </authorization>

  </system.web>

  <location path="register.aspx">    <!--path here is path to your register.aspx page-->
    <system.web>
      <authorization>
        <allow users="*"/>       <!--this will allow access to everyone to register.aspx-->
      </authorization>
    </system.web>
  </location>

</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2018-04-30
    • 2020-07-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多