繁体   English   中英

ASP.NET web.config表单身份验证,拒绝匿名用户,允许匿名访问单个文件

[英]ASP.NET web.config Forms Authentication, deny anonymous users, allow anonymous access for single files

我在这里阅读本教程: 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?

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

    <location path="Login.aspx">
      <system.web>
        <authorization>
          <allow users="*" />
        </authorization>
      </system.web>
    </location>
   <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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM