gpt4 book ai didi

c# - Application_Error 在本地主机上呈现页面,但不在生产 (www) 上呈现页面

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:01 25 4
gpt4 key购买 nike

我有一个呈现错误页面的 Application_Error:

    private void Application_Error(object sender, EventArgs e)
{

Exception exception = Server.GetLastError();

// A good location for any error logging, otherwise, do it inside of the error controller.

Response.Clear();
HttpException httpException = exception as HttpException;

RouteData routeData = new RouteData();

routeData.Values.Add("controller", "Error");
routeData.Values.Add("action", "Index");

// Clear the error, otherwise, we will always get the default error page.
Server.ClearError();

routeData.Values.Add("id", httpException.GetHttpCode());
Response.StatusCode = httpException.GetHttpCode();
Context.Response.ContentType = "text/html";

// Call the controller with the route
IController errorController = new ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));


}

在我的本地机器上无缝运行。当我将其投入生产时,它呈现常规的 asp 404 页面,而不是 Controller 应该为服务器提供的页面。

即使在生产服务器上,当我使用 localhost 而不是 www 时它也能正常工作。

我应该补充一点,我在 web.config 中没有针对客户错误的配置。我试过将它们关闭,但也无济于事。

对我来说,似乎是 url 造成了这种情况,但无法弄清楚原因/方式。

知道如何解决这个问题吗?

最佳答案

请在您的 Application_Error 方法中尝试添加此...

Response.TrySkipIisCustomErrors = true; 

关于c# - Application_Error 在本地主机上呈现页面,但不在生产 (www) 上呈现页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24600874/

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