当其余页面需要授权时,允许公共访问两个ASP.NET WebForm页面

时间:2012-01-24 17:05:28

标签: web-config webforms

我们正在为我们的应用添加几页,不需要在登录后锁定。我如何打开两页以便公开访问。

这是我的Web.config:

<authentication mode="Forms">
    <forms name=".ORGANIZATION" loginUrl="Default.aspx" protection="All" timeout="120"/>
</authentication>
<authorization>
    <deny users="?"/>
    <allow users="*"/>
</authorization>

我们希望page1.aspx和page2.aspx是公开的。我怎么能允许呢?

2 个答案:

答案 0 :(得分:3)

您可以在web.config中添加location来免除它们:

<configuration>
    <!-- The rest of your web.config -->
    <system.web>
        <authentication mode="Forms">
            <forms name=".ORGANIZATION" loginUrl="Default.aspx" protection="All" timeout="120"/>
        </authentication>
        <authorization>
            <deny users="?"/>
            <allow users="*"/>
        </authorization>
    </system.web>
    <location path="page1.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
    <location path="page2.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>
</configuration>

答案 1 :(得分:1)

在经过身份验证的网站中,您可以使用Location中的web.config元素指定可以匿名访问网页。

在此web.config部分中,任何人都可以在未经过身份验证的情况下访问RecoverPassword页面,但没有人可以在未经过身份验证的情况下访问Admin文件夹中的页面。

<configuration>
  <location path="RecoverPassword.aspx">   // specify file    \   only specify one --
  <location path="Admin" >                 // specify folder  /   either file or folder
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>

  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="UserLogin.aspx" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
  </system.web>
</configuration>
相关问题