![](/img/trans.png)
[英]Static file not served through IIS but serving through localhost - ASP.NET Core 3.1 MVC & C#
[英]Allow IIS 7.5 from serving static files through ASP.NET pipeline
我只有幾個文件夾,它們被排除在web.config中的內容,Javascript和腳本之外。 請幫助我實現這一目標。
這是配置:
<location path="TechDocs">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<location path="Scripts">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Content">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Javascript">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
這就是我們使用的
<location path="Scripts">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Css">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
您必須確保您沒有http模塊來攔截請求並針對上述任何資源發出401 Unauthorized
以下是我的路由配置,以便MVC不會將請求意外路由到MVC,您可以應用
routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(ico|css|js|gif|jpg|woff|eot|svg|eot|ttf|otf)(/.*)?" });
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.wdgt/{*pathInfo}");
routes.IgnoreRoute("ChartImg.axd/{*pathInfo}");
routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" });
routes.IgnoreRoute("{resource}.svc");
我認為您無法做到。
根據Microsoft的經驗,一般的經驗法則是,“拒絕”總是擊敗“允許”,因此,如果您拒絕在根級別進行訪問,則除非能夠刪除權限,否則您將無法在較低級別授予訪問權限從根級別繼承。 我認為沒有辦法刪除那些繼承的權限。 我試着放下,但這是無效的。
因此,您必須在每個需要拒絕訪問的文件夾上設置“拒絕所有用戶”,您不能將其默認設置為“拒絕”。 另外,如果所有用戶都拒絕了IIS站點中的內容,也許您不應該擁有大量內容?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.