C# 应用程序_错误在本地主机上呈现页面,但不在生产(www)上呈现页面

C# 应用程序_错误在本地主机上呈现页面,但不在生产(www)上呈现页面,c#,asp.net-mvc,iis,global-asax,C#,Asp.net Mvc,Iis,Global Asax,我有一个应用程序错误,它会呈现一个错误页面: 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.

我有一个应用程序错误,它会呈现一个错误页面:

    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页面,而不是控制器应该呈现给服务器的页面

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

我应该补充一点,我在
web.config
中没有自定义错误的配置。我试着把它们关掉,但也没用

对我来说,似乎是url导致了这种情况,但无法找出原因/方式


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

在你的应用程序中\u错误方法请尝试添加这个

Response.TrySkipIisCustomErrors = true; 

愚蠢的问题:你有办法确保你的
设置。开发模式
在生产中返回预期值吗?有时我忽略了最简单的事情…@DavidTansey,这在生产中是错误的。它在应用程序中是硬编码的,并且总是返回false。您是否在iis中打开了详细错误?这有时会用标准页面替换错误消息。