2013-05-14 23 views
1

我現在有一個登錄系統來阻止所有未經過身份驗證的用戶查看我網站的內容。我可以確認登錄作品。 但是我現在面臨的問題是使用我的web.config文件。我可以阻止未經驗證的用戶查看主頁面(即www.mysite.com),從而加載index.php。用戶雖然仍然可以訪問www.mysite.com/index.php而不登錄登錄目的。Web.Config來封鎖整個網站

我的web.config只處理主頁面和我在根目錄下的任何.aspx文件。 以下是我的web.config代碼。我已經找了一段時間的解決方案,並沒有找到一種方法,使web.config工作的整個網站。此外,它位於根(和我的網站使用wordpress)。因爲我已經花了相當長一段時間對這個

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.web> 

    <compilation defaultLanguage="c#" debug="false" /> 
    <customErrors mode="Off" /> 
    <authentication mode="Forms"> 
     <forms 
      name=".myCookie" 
      loginUrl="http://www.mysite.com" 
      domain="mysite.com" 
      protection="All" 
      timeout="120" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true" 
     /> 
    </authentication> 

<authorization> 
      <allow roles="AA,BB" /> 
      <deny users="*" /> 
     </authorization> 

    <machineKey 
     validationKey="xxxxxxx" 
     decryptionKey="xxxxxxx" 
     validation="SHA1" 
    /> 
    <sessionState mode="Off" /> 
</system.web> 

<system.webServer> 
<defaultDocument> 
     <files> 
      <add value="index.php" /> 
     </files> 
    </defaultDocument> 
<rewrite> 
    <rules> 
    <rule name="wordpress" patternSyntax="Wildcard"> 
     <match url="*" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="index.php" /> 
    </rule> 
</rules> 
</rewrite> 
</system.webServer> 

</configuration> 

任何幫助,將不勝感激,我覺得這應該是一個簡單的解決方案。我也在運行IIS 7.

總結我的問題,我需要web.config文件來阻止對所有類型的文件(php,.txt等)的訪問,而不僅僅是根URL和.aspx文件。

謝謝

+0

作爲更新的事。看來我被system.web vs system.webserver這兩行弄糊塗了。由於我在運行IIS7,因此我應該將驗證放入配置的web服務器部分。 – Jingles177

回答

2

所以當我評論事實證明的System.Web是IIS6和system.webServer用於iis7,這是我運行的。 我對system.web的授權規則是正確的,所以任何.net文件都按預期被阻止,但由於iis7管道集成,任何其他文件擴展名都不會受到影響。 解決這個我從實測值: http://blogs.msdn.com/b/rakkimk/archive/2007/11/28/iis7-making-forms-authentication-to-work-for-all-the-requests.aspx?Redirected=true

它與線前提=「」

0

通常情況下,除非你使用「位置」標籤的安全性在一個web.config將採取對整個網站的效果。

這是我的片段; 注意,loginURL是特定頁面

<authentication mode="Forms"> 
    <forms loginUrl="~/public/Login.aspx" slidingExpiration="true" timeout="45" /> 
</authentication> 
<authorization> 
    <deny users="?"/> 
</authorization> 

的?代表匿名用戶 實際上得到的CSS正常工作你就必須添加以下授權任何人訪問這些文件:

<!-- Allow Anonymous Access to the Themes Folder --> 
<location path="App_Themes" > 
<system.web> 
    <authorization> 
    <allow users="*" /> 
    </authorization> 
</system.web> 
</location> 
+0

嗨史蒂夫謝謝你的回覆。 不幸的是,我不相信你的回覆是我在尋找什麼,或者我不知道如何實現它。 例如,index.php文件位於根目錄。如果我設置了<位置路徑=「index.php」>並阻止匿名用戶訪問那裏,他們仍然可以出於某種原因。 – Jingles177

+0

我建議將您的loginURL更改爲登錄頁面的相對路徑,這是您懷疑的主要問題,並拒絕來自整個站點的匿名用戶。刪除您允許的角色,直到您獲得經過身份驗證的任何人的工作。 – Steve

+0

好的,我會給它一個鏡頭,併發布如果它的工作。我之前應該提到登錄頁面不在Wordpress頁面上。如果你嘗試訪問Wordpress頁面,它應該重定向到一個你可以登錄的不同的URL,然後這個cookie允許你訪問Wordpress頁面。 – Jingles177