2010-11-26 102 views
3

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

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

任何帮助,将不胜感激。

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

System.Web.HttpException:文件 'test.aspx'不存在。在 System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)在 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,布尔noBuild,布尔 allowCrossApp,布尔 allowBuildInPrecompile)在 System.Web.Compilation .BuildManager.GetVPathBuildResultWithNoAssert(HttpContext的 上下文,VirtualPath virtualPath, 布尔noBuild,布尔 allowCrossApp,布尔 allowBuildInPrecompile)在 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext的上下文中, 布尔allowCro ssApp,布尔 noAssert)在 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,类型requiredBaseType, HttpContext的上下文中,布尔 allowCrossApp,布尔noAssert)在 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext的 上下文中,字符串的RequestType, VirtualPath virtualPath,字符串 physicalPath)在 System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,布尔&已完成同步)

+0

我有同样的问题。我在我的web.config中定义了一个自定义的404页面,它仅适用于非.aspx文件。 – DavidJBerman 2011-11-25 14:58:47

回答

2

您可以尝试下列操作之一:

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

    <customErrors mode="On"> 
        <error statusCode="404" redirect="404.aspx"/> 
    </customErrors> 
    
  2. 添加404.aspx页面,并设置状态码到:

    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; 
}