ASP.NET 2.0认证项的配置

在ASP.NET2.0中,如果根目录允许匿名用户访问,而根目录下的一个页面(如Info.aspx)必须要登录(假设登录页面为login.aspx)后才能访问,根目录下的web.config文件必须这样配置:

<?xml version="1.0"?>

<configuration>
 <appSettings>
 </appSettings>
 <connectionStrings>
 </connectionStrings>

  <system.web>
    <compilation debug="true"/>

    <!--<authentication mode="Windows"/>-->
    <authentication mode="Forms">
      <forms loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
    </authentication>

    <authorization>

      <!--允许匿名-->
      <allow users="?"/>

    </authorization>

  </system.web>

  <location path="Info.aspx">
    <system.web>

      <!--认证项配置(在为一个单独页面指定认证信息时,authentication节只能从这个目录继承,不能单独设置)-->
      <!--
      <authentication mode="Forms">
        <forms name=".www.cnpp.info" loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
      </authentication>
      -->

      <!--用户访问控制-->
      <authorization>

        <!--阻止匿名-->
        <deny users="?"/>

      </authorization>
    </system.web>
  </location>

 
</configuration>

 

也就是在需要认证的页面配置节中不能配置authentication项,只能在在根目录中配置authentication项,Info.aspx从根目录继承. 否则会出现这样的错误: "在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误 "

最后验证了一个是<authentication> <form  节只能出现在根站点或应用程序站点中

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值