允许使用ASP.Net Forms身份验证访问未经身份验证的用户到特定页面

时间:2010-09-02 15:07:04

标签: asp.net forms-authentication

我正在使用ASP.Net Forms身份验证。我的Web.config看起来像这样。

    <authentication mode="Forms">
      <forms loginUrl="login.aspx"/>
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

所以目前每个aspx页面都需要身份验证。

我想允许甚至未经身份验证的用户访问名为special.aspx的特定页面。 我怎么能这样做?

4 个答案:

答案 0 :(得分:53)

查看MS Support

上的示例
<configuration>
    <system.web>
        <authentication mode="Forms" >
            <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
            </forms>
        </authentication>
<!-- This section denies access to all files in this 
application except for those that you have not explicitly 
specified by using another setting. -->
        <authorization>
            <deny users="?" /> 
        </authorization>
    </system.web>
<!-- This section gives the unauthenticated 
user access to the ThePageThatUnauthenticatedUsersCanVisit.aspx 
page only. It is located in the same folder 
as this configuration file. -->
        <location path="ThePageThatUnauthenticatedUsersCanVisit.aspx">
        <system.web>
        <authorization>
            <allow users ="*" />
        </authorization>
        </system.web>
        </location>
<!-- This section gives the unauthenticated 
user access to all of the files that are stored 
in the TheDirectoryThatUnauthenticatedUsersCanVisit folder.  -->
        <location path="TheDirectoryThatUnauthenticatedUsersCanVisit">
        <system.web>
        <authorization>
            <allow users ="*" />
        </authorization>
        </system.web>
        </location>
</configuration>

答案 1 :(得分:16)

将以下内容放入web.config中:

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

答案 2 :(得分:2)

<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>
  

有关详细信息,请参阅以下链接

     

http://weblogs.asp.net/gurusarkar/setting-authorization-rules-for-a-particular-page-or-folder-in-web-config

答案 3 :(得分:2)

允许所有人访问特定网页

有时您希望允许公共访问某个页面,并希望仅限访问已记录/已验证的用户访问该站点的其余部分。不允许匿名访问。假设您的special.aspx位于您网站的根文件夹中。在您网站的根文件夹的web.config中,您需要进行以下设置。

 <configuration>
    <system.web>

    <authentication mode="Forms"/>

       <authorization> <deny users="?"/>  //this will restrict anonymous user access
       </authorization>

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

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