2010-09-02 129 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> 
相關問題