3

我有一个具有 Global_Asax 和自定义错误页面的 Web 应用程序。当用户试图进入一个不存在的无效页面时,Application_Error 在 Global_asax 中被触发,并且记录的异常并不是真正的异常(您可以在下面查看异常详细信息)。我不想在 global_asax 中处理这种情况,而是在 IIS 中处理。我还尝试输入以 .asp 和 .html 结尾的无效路径,它们工作正常(它们不是以 global_asax 结尾,而是在默认的 404 页面中)。

我需要知道我必须从 IIS7 管理器更改哪个设置。

任何帮助,将不胜感激。

错误 - 文件“/restricted/ff.aspx”不存在。

System.Web.HttpException:文件“test.aspx”不存在。在 System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) 在 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) 在 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context , VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) 在 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) 在 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,类型 requiredBaseType, HttpContext context, Boolean allowCrossApp,

4

1 回答 1

2

您可以尝试以下方法之一:

  1. 编辑自定义错误的web.config文件:

    <customErrors mode="On">
        <error statusCode="404" redirect="404.aspx"/>
    </customErrors>
    
  2. 添加一个404.aspx页面并将状态码设置为404

    public partial class _04 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.StatusCode = 404;
        }
    }
    

如果它也不能帮助您尝试此操作(它可能会被您的母版页重置):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.StatusCode = 404;
}
于 2011-11-28T12:04:04.793 回答