gpt4 book ai didi

c# - Global_Asax Application_Error Fired 而不是默认的 IIS7 404 Page Not Found Page

转载 作者:行者123 更新时间:2023-11-30 17:20:13 26 4
gpt4 key购买 nike

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

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

如有任何帮助,我们将不胜感激。

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)

最佳答案

您可以尝试其中之一:

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

关于c# - Global_Asax Application_Error Fired 而不是默认的 IIS7 404 Page Not Found Page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4285817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com