2012-07-30 40 views
3

我MVC3應用程序顯示403自定義錯誤頁,404和500個狀態碼,但瀏覽到的trace.axd顯示以下YSOD:如何獲得MVC3中trace.axd的自定義錯誤頁面?

Server Error in '/' Application. 

    Trace Error 

    Description: Trace.axd is not enabled in the configuration file for this application. Note: Trace is never enabled when <deployment retail=true /> 

    Details: To enable trace.axd, please create a <trace> tag within the configuration file located in the root directory of the current web application. This <trace> tag should then have its "enabled" attribute set to "true". 

    <configuration> 
     <system.web> 
      <trace enabled="true"/> 
     </system.web> 
    </configuration> 

所以我有微量禁用,這是好的,但爲什麼沒有顯示500頁面,因爲這是從服務器返回的403頁面?我真的很高興404,403,或500真的 - 只要它不是一個醜陋的黃色屏幕!

編輯:我在本地主機上運行時得到了一個500與YSOD,但它實際上是一個403服務器上接近我所期望的 - 但仍然沒有自定義錯誤頁面。這也是在服務器上略有不同的標準錯誤頁:

Server Error in '/' Application. 

Trace Error 

Description: The current trace settings prevent trace.axd from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable trace.axd to be viewable on remote machines, please create a <trace> tag within the configuration file located in the root directory of the current web application. This <trace> tag should then have its "localOnly" attribute set to "false". 

<configuration> 
    <system.web> 
     <trace localOnly="false"/> 
    </system.web> 
</configuration> 

回答

1

由於沒有回答,我問@shanselman在Twitter上,誰建議<deployment retail = "true" />可能解決它,但它仍然返回相同YSOD。

最後我通過刪除routes.IgnoreRoute(「{resource} .axd/{* pathInfo}」)來解決它。從路由配置。這看起來不太合適,但它起作用。

1

刪除@Cosmologinaut建議的IgnoreRoute並不適合我,因爲他說感覺不對。我發現了一個更好的解決方法是刪除跟蹤HTTP處理程序在Web.config文件中:

<system.webServer> 
    <!-- remove TraceHandler-Integrated - Remove the tracing handlers so that navigating to /trace.axd gives us a 
     404 Not Found instead of 500 Internal Server Error. --> 
    <handlers> 
     <remove name="TraceHandler-Integrated" /> 
     <remove name="TraceHandler-Integrated-4.0" /> 
    </handlers> 
    </system.webServer> 

導航現在/trace.axd給了我們一個404未找到,而不是500內部服務器錯誤。

相關問題