0
我的MVC應用程序使用如下因素網址:如何轉發一個網址到404錯誤頁面上MVC
/Content/ /Content/style.css /Content/image.png
我想創建前進的URL /Content/
應該被轉發到404錯誤。所有其他網址都應該有效。怎麼做?
我試過下面的解決方案,但它將所有文件從/ Content /轉發到404錯誤頁面,但我只想阻止主目錄。
Web.config文件:
<validation validateIntegratedModeConfiguration="false" />
<handlers>
...
<add name="hideDirectoryContent" verb="*" path="Content" type=" NameSspace.NoAccessHandler"/>
</handlers>
</system.webServer>
NoAccesHandler.cs:
public class NoAccessHandler : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.StatusCode = 404;
}
#endregion
}
但如果其他路徑像'/ Content/file1.jpg'還在工作? –