我的 ASP.NET 專案中有一個子目錄,其中包含實用程式檔案。程式碼在運行時需要它們,但我不希望它們在網路上可見。
Web.config 檔案中阻止所有使用者存取單一子目錄及其所有內容的語法是什麼?
答案1
IIS 7 有一個新的「請求過濾」功能。您可能會想要使用隱藏段配置:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="BIN"/>
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
這導致http://你的網站/bin無法提供服務(但是http://你的網站/二進制仍然有效)
查看: http://learn.iis.net/page.aspx/143/how-to-use-request-filtering
答案2
您的問題是,如果 IIS 只是返回文件,則 ASP.Net 將永遠沒有機會進行幹擾。我相信這可以透過啟用基於表單的身份驗證和相當多的混亂來完成,但我只需將文件移到 wwwroot 資料夾之外。
JR
答案3
這應該有效:
<configuration>
<location path="FolderName">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
</configuration>
答案4
web.config
這是一個老問題,但這是Web 伺服器路徑中任何目錄的簡單插入。它刪除所有使用者角色,然後將預設存取權限設為拒絕。簡單且無需配置。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Deny" users="*" />
</authorization>
</security>
</system.webServer>
</configuration>