2010-09-02 79 views
34

我正在使用ASP.Net窗体身份验证。我的Web.config看起来像这样。允许未经身份验证的用户访问特定页面使用ASP.Net窗体身份验证

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

因此,目前每个aspx页面都需要验证。

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

+0

你有没有想过这一个? – 2010-09-07 04:50:37

回答

44

就以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> 
+0

当使用这种技术用于''时,它允许未经身份验证的用户访问我想要的特定页面(“yay”),但仍会提示输入他们的凭据?你可以关闭它,并查看页面就好了,但我想知道如何禁用特定页面的“需要身份验证”? – 2017-01-03 21:50:41

+0

@TrevorNestman您是否正在加载页面上的其他资源,如图像等?这可能是他们提示进行身份验证。 – dnolan 2017-01-26 10:17:44

+0

@dnolan感谢您的回复。我能弄明白。我问他们在视图中扮演了什么角色,所以我很确定这就是提示它的原因。 – 2017-01-26 15:26:46

15

看看例子放入你的web.config以下:

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

允许所有人访问特定页面

有时你想允许一些页面的公共访问,并希望限制只能访问到登录/身份验证的用户.i.e网站的其余部分。不允许匿名访问。假设您的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> 
相关问题