2011-09-29 138 views
8

我必須密碼保護Windows服務器上的目錄。該頁面應顯示位於該目錄中的文件列表。我沒有任何以前的知識(以前只使用過Apache),所以我試圖通過Google搜索一起黑客攻擊。 (對於知道他們在做什麼的人,我確信這看起來很荒謬)使用web.config密碼保護文件夾

我現在所擁有的是我得到一個登錄彈出窗口,但沒有密碼正在工作。我們在我們的SQL數據庫中爲adminusers提供了一個表,因此從那裏獲取用戶登錄或將登錄信息嵌入到配置文件中是沒有問題的。我需要的只是密碼保護的文件夾。

這是我現在在我的web.config文件中,位於應該受密碼保護的文件夾中。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.web> 
     <authentication mode="Forms"> 
      <credentials passwordFormat="Clear"> 
       <user name="test" password="test" /> 
      </credentials> 
     </authentication> 
     <authorization> 
      <allow users="test" /> 
      <deny users="*" /> 
     </authorization> 
    </system.web> 
    <system.webServer> 
     <directoryBrowse enabled="true" /> 
     <security> 
      <authentication> 
       <anonymousAuthentication enabled="false" /> 
       <basicAuthentication enabled="true" /> 
       <windowsAuthentication enabled="false" /> 
      </authentication> 
     </security> 
    </system.webServer> 
</configuration> 

希望這是一個簡單的問題,並提前感謝任何幫助! :)

+0

你有基本身份驗證的混合和窗體身份驗證回事,它看起來像:

<configuration> <system.web> <authentication mode="Forms"> <credentials passwordFormat="Clear"> <user name="test" password="test" /> </credentials> </authentication> <authorization> <allow users="test" /> <deny users="*" /> </authorization> </system.web> <location path="admin"> <system.web> <authorization> <allow roles="admin" /> <deny users="*"/> </authorization> </system.web> </location> <system.webServer> <directoryBrowse enabled="true" /> <security> <authentication> <anonymousAuthentication enabled="false" /> <basicAuthentication enabled="true" /> <windowsAuthentication enabled="false" /> </authentication> </security> </system.webServer> </configuration> 

可以使用這樣的加密用戶信息。如果您希望測試/測試在彈出窗口中工作,則不會。基本身份驗證需要服務器上的Windows用戶名/密碼,我相信。你需要走這條路線,或者擺脫基本的身份驗證,並實施其餘的FormsAuthentication:登錄頁面等。 –

+0

您是否認爲仍然可以通過會話等進行「自定義」登錄並使用「directoryBrowse」? – hesselbom

+1

是否有可能以某種方式使用彈出窗口作爲登錄而不是表單? – hesselbom

回答

3

試試這個:

aspnet_regiis.exe -pef "sectionName" C:\Path\To\Your\Application 
+0

我該把這個放在哪裏?在我的問題中提到的根或配置文件中的配置文件?這將從哪裏獲得用戶信息? – hesselbom

+1

將它放在web.config文件中,位於system.web部分之外。 –

+0

我編輯了我的答案,告訴你你會把它放在哪裏。 –