2010-01-27 60 views
5

我想在我的網站上使用FormsAuthentication來保護我的靜態文件,所以我按照標題爲「爲整個應用程序啓用表單身份驗證」的http://learn.iis.net/page.aspx/244/how-to-take-advantage-of-the-iis7-integrated-pipeline/FormsAuthentication在訪問網站根目錄時重定向到登錄頁面

現在儘管如此,當我嘗試直接訪問http://www.mysite.com網站時,我將其重定向到http://www.mysite.com/Login.aspx?ReturnUrl=%2f而不是使用我設置的DefaultDocument。我可以通過訪問http://www.mysite.com/Home.aspx而沒有任何問題進入我的默認文檔,因爲它設置爲允許匿名訪問。

有什麼我需要添加到我的web.config文件,使iis7允許匿名訪問根?我嘗試使用匿名訪問進行添加,但沒有這樣的運氣。

任何幫助將不勝感激。


主頁和登錄表單都允許匿名。

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

登錄表單設置爲loginUrl

<authentication mode="Forms"> 
    <forms protection="All" loginUrl="Login.aspx"> 
    </forms> 
</authentication> 

默認文檔設置爲Home.aspx

<defaultDocument> 
    <files> 
    <add value="Home.aspx" /> 
    </files> 
</defaultDocument> 

我沒有刪除任何IIS7默認文檔。但是,Home.aspx首先是優先考慮的。

+0

發佈您的web.config設置。 – Bryan 2010-01-28 01:40:48

+0

另外...是Home.aspx在IIS中的默認文檔中列出的* only *文件? – Bryan 2010-01-28 01:44:35

+0

重複的http://stackoverflow.com/questions/3824951/forms-authentication-ignoring-default-document – Gh0sT 2011-04-15 15:33:58

回答

-1

你有沒有嘗試這個辦法:

<authorization>  
    <allow users="?" /> 
</authorization> 

我認爲這會解決它。

+2

它並沒有解決任何問題 - 它只是完全禁止授權,從而破壞了授予它的目的 – Andrey 2011-05-06 21:07:17