在此上下文错误中,Application_Error方法(global.asax.cs)中的请求不可用

时间:2019-09-23 15:29:25

标签: asp.net-web-api custom-errors

发生错误时,我试图重定向到自定义错误页面,并且出现此提示错误“在此上下文中请求不可用”。我在Application_Start()方法中遇到错误,并且在尝试执行Server.Transfer(path)时调用Application_error,但它抛出“请求不可用”错误

我已经尝试过使用web.config进行所有操作(添加customError属性,尝试使用httpErrors属性进行尝试),但是我得到的只是一个运行时错误

受保护的void Application_Start()         {

        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);


    }

受保护的void Application_Error(对象发送者,EventArgs e)         {

        string path = @"~\web\templates\unhandledErrorPage.html";
        Server.Transfer(path, true);

    }

和我的webConfig:

带有httpErrors:                                 path =“〜\ web \ templates \ unhandledErrorPage.html” />
       

具有customErrors:

            

我故意抛出ApplicationError,除了将我重定向到我创建的自定义页面外,我遇到了可悲的运行时错误

0 个答案:

没有答案