Global_Asax Application_Error 被触发,而不是默认的 IIS7 404 页面未找到页面

发布于 2024-10-04 23:39:33 字数 1376 浏览 2 评论 0原文

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

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

任何帮助将不胜感激。

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

System.Web.HttpException:文件 “test.aspx”不存在。在 System.Web.UI.Util.CheckVirtualFileExists(虚拟路径 虚拟路径)位于 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(虚拟路径 virtualPath,布尔值 noBuild,布尔值 允许跨应用程序,布尔值 允许BuildInPrecompile)在 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext 上下文,虚拟路径虚拟路径, 布尔值 noBuild, 布尔值 允许跨应用程序,布尔值 允许BuildInPrecompile)在 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath、HttpContext 上下文、 布尔值allowCrossApp,布尔值 无断言)在 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,类型需要BaseType, HttpContext 上下文,布尔值 allowCrossApp,布尔值 noAssert) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext 上下文,字符串请求类型, 虚拟路径 虚拟路径,字符串 物理路径)在 System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 在 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,布尔值&同步完成)

I have a Web Application which has Global_Asax and a Custom Error Page. When user tries to enter to an invalid page which doesn't exist, Application_Error is fired in Global_asax and exception is logged which isn't really an exception (You can see the exception details below). I don't want to handle this case in global_asax but rather in IIS. I've also tried to enter invalid paths ending with .asp and .html and they work fine(They don't end in global_asax but rather in default 404 page).

I need to know which setting I have to change from IIS7 Manager.

Any help would be appreciated.

Error - The file '/restricted/ff.aspx'
does not exist.

System.Web.HttpException: The file
'test.aspx' does not exist. at
System.Web.UI.Util.CheckVirtualFileExists(VirtualPath
virtualPath) at
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath
virtualPath, Boolean noBuild, Boolean
allowCrossApp, Boolean
allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext
context, VirtualPath virtualPath,
Boolean noBuild, Boolean
allowCrossApp, Boolean
allowBuildInPrecompile) at
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath
virtualPath, HttpContext context,
Boolean allowCrossApp, Boolean
noAssert) at
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath
virtualPath, Type requiredBaseType,
HttpContext context, Boolean
allowCrossApp, Boolean noAssert) at
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext
context, String requestType,
VirtualPath virtualPath, String
physicalPath) at
System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at
System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤寂小茶 2024-10-11 23:39:34

您可以尝试以下其中一项:

  1. 编辑web.config文件以查找自定义错误:

    
        <错误状态代码=“404”重定向=“404.aspx”/>
    
    
  2. 添加 404.aspx 页面并将状态代码设置为 404:

    公共分部类_04:System.Web.UI.Page
    {
        protected void Page_Load(对象发送者,EventArgs e)
        {
            响应.StatusCode = 404;
        }
    }
    

如果这对您没有帮助,也可以尝试此操作(可能会由您的母版页重置):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.StatusCode = 404;
}

You can try one of these:

  1. Edit the web.config file for custom errors:

    <customErrors mode="On">
        <error statusCode="404" redirect="404.aspx"/>
    </customErrors>
    
  2. Add a 404.aspx page and set the status code to 404:

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

If it doesn't help you try this as well (it might be reset by your masterpage):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.StatusCode = 404;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文