2012-01-04 62 views
2

我正在使用此SO Question中詳細介紹的解決方案。我以前在其他網站上使用過它,它的工作正常,並且它在我的開發盒上工作。但是,當我發佈到我們的Windows VPS時,錯誤將返回標準的IIS錯誤頁面。MVC3自定義錯誤頁面在dev中工作,不在服務器上

我從來沒有管理過一個網絡服務器,我不知道我需要檢查什麼設置來弄清楚爲什麼它不返回我設置的自定義錯誤。我已經嘗試設置應用程序的.net錯誤頁面關閉和打開,默認頁面設置爲根網站,以及只是'/'。

我也嘗試設置錯誤頁面(7.5中的iis下)以定製和詳細。

這些都不會對返回的錯誤頁面有任何影響。我在這裏做錯了什麼?

+0

是你看到了什麼錯誤頁面?這會讓我們知道什麼是錯誤。從那裏可以找出接下來要嘗試的設置。 – 2012-01-04 18:40:08

+0

它是標準iis錯誤頁面。以下是我在谷歌上找到的一個示例:http://www.west-wind.com/Weblog/images/200901/WindowsLiveWriter/Response.TrySkipIisCustomErrors_9A81/ServerError500_5436e95f-b1b5-46eb-80ab-0769a875117d.png – Tyrsius 2012-01-04 18:42:15

回答

1

我記得有類似的問題,我加入這行代碼

protected void Application_Error() 
{ 
var exc = Server.GetLastError(); 
var httpExc = exc as HttpException; 
Response.Clear(); 
Server.ClearError(); 
var routeData = new RouteData(); 
routeData.Values["controller"] = "Error"; 
routeData.Values["action"] = "General"; 
routeData.Values["exception"] = exc; 
Response.StatusCode = 500; 
if (httpExc != null) 
{ 
    Response.StatusCode = httpExc.GetHttpCode(); 
    routeData.Values["action"] = "Http404"; 
    routeData.Values["exception"] = httpExc; 
} 
Response.TrySkipIisCustomErrors = true; //this fixed it 
IController errorsController = new WWS_Website.Controllers.ErrorController(); 
var rc = new RequestContext(new HttpContextWrapper(Context), routeData); 
errorsController.Execute(rc); 

} 
+0

這是做到了,謝謝! – Tyrsius 2012-01-05 00:06:24

+0

我還發現這與在各種主機上的服務器上的部署相關:http://stackoverflow.com/q/1706934/964043 – dmarietta 2014-04-07 16:11:48

0

您可以使用web.config文件的system.webServer部分中的httpErrors部分替換標準的IIS錯誤頁面。這是system.web中的customErrors部分的補充。

<system.webServer> 
    ... 
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> 
     <remove statusCode="400" subStatusCode="-1" /> 
     <error statusCode="400" prefixLanguageFilePath="" 
      path="/errors/400" responseMode="ExecuteURL" /> 
     <remove statusCode="404" subStatusCode="13" /> 
     <error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" 
      path="/errors/file-upload-too-large" responseMode="Redirect" /> 
     <remove statusCode="404" subStatusCode="-1" /> 
     <error statusCode="404" prefixLanguageFilePath="" 
      path="/errors/404" responseMode="ExecuteURL" /> 
     <remove statusCode="403" subStatusCode="-1" /> 
     <error statusCode="403" prefixLanguageFilePath="" 
      path="/errors/403" responseMode="ExecuteURL" /> 
    </httpErrors> 
+0

這不符合我正在使用的解決方案。請參閱鏈接的SO問題 – Tyrsius 2012-01-04 20:13:51

+0

您說這適用於您的開發機器,但不適用於IIS。在開發中,您是否使用IIS Express進行測試?還是卡西尼? – danludwig 2012-01-04 20:26:58

+0

我正在使用卡西尼 – Tyrsius 2012-01-04 21:15:34

相關問題