[英]IIS changing the IE11 document mode from 11 (Default) to 7 (Default) when browsing to a site
[英]How to stop directory browsing of a web site but also allow default document
當您嘗試訪問Web服務器上的目錄時,您會收到403消息,而通常更希望獲得404消息,因此您不會向黑客提供有關文件夾存在的線索。
我以為我找到了解決此問題的最終方法-通過將其添加到web.config system.webServer中:
<handlers>
<add name="StopDirectoryBrowsing" path="*." resourceType="Directory" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" />
</handlers>
當您嘗試訪問目錄時,這將正確引發404。
但是可悲的是,它殺死了頂層的默認文檔機制。
任何人都可以提出上述的一種變體,該變體允許默認文檔工作,但仍保護子目錄。
這實際上並不會更改返回的狀態代碼,但是您可以使用<customErrors>
隨意重定向:
<customErrors mode="RemoteOnly" defaultRedirect="~/redirect/error-status.aspx">
<error statusCode="403" redirect="~/redirect/access-denied.aspx" />
<error statusCode="404" redirect="~/redirect/file-not-found.aspx" />
</customErrors>
您可以根據需要將每個狀態代碼重定向到單個頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.