2015-03-31 28 views
0

我試圖在VS Express 2013中用我的MVC4應用程序進行調試。未找到MVC CustomError

在視圖中,我添加了一個無意義的鏈接,如<a href="blah.asf">link,</a>,但是當我單擊鏈接時,看不到預期的視圖,我看到IIS頁面。

我通過創建一個ErrorController這是

public class ErrorController : Controller 
{ 
    public ActionResult Index() 
    { 
     return View(); 
    } 
} 

我的觀點仍然是默認這樣做,我也沒有更新。

我的webconfig是

<customErrors mode="On" defaultRedirect="~/Error"> 
    </customErrors> 

的路由是默認!

的IIS消息是

HTTP Error 404.0 - Not Found 

如果我在http://localhost:53258/error/鍵入然後我看到的頁面,這表明該映射是好的。

我做錯了什麼?

+0

我不知道爲什麼您認爲顯示錯誤的唯一要求是創建n'ErrorController'非常不是這種情況。 – 2015-03-31 16:35:49

+0

公平地假設〜/錯誤路由被映射了嗎? – 2015-03-31 16:37:24

+0

@ErikPhilips,我沒有,因此更新到web.config和視圖... – MyDaftQuestions 2015-03-31 16:43:10

回答

0

檢查這在你的web.config,並添加它,如果你沒有的話:

<httpErrors errorMode="Custom" existingResponse="PassThrough" /> 
+0

我收到「不允許存在的現有響應」屬性的錯誤。我試過了,但沒有區別 – MyDaftQuestions 2015-03-31 16:41:25

0

嘗試更新customErrors節點補充一點:

<error statusCode="404" redirect="~/Error" /> 

因此,您的自定義錯誤部分將如下所示:

<customErrors mode="On"> 
    <error statusCode="404" redirect="~/Error" /> 
</customErrors>