기본적으로 MVC 템플릿은 HandleErrorAttribute att를 구현합니다. 우리는 CustomErrors가가의 web.config에 설정되어있는 경우
가
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
filters.Add(new HandleErrorAttribute());
}
HandleErrorAttribute 기본 오류 페이지로 사용자를 리디렉션 Global.asax에이를 찾아 (또는 App_Start \ FilterConfig.cs에서 MVC4의 경우) 할 수 있습니다.
<system.web>
<customErrors mode="On" defaultRedirect="Error.cshtml" />
</system.web>
구문 : 아래 그림과 같이
이 HandleErrorAttribute 필터에 의한 사용자 지정 오류 처리를 사용하려면, 우리는 응용 프로그램의 web.config의 system.web 섹션에 customErrors에 요소를 추가 할 필요가
<customErrors defaultRedirect="url" mode="On | Off | RemoteOnly">
</customErrors>
다음과 같이 별도의보기를 사용하여 사용자를 오류 상태 코드를 기반으로 특정보기로 리디렉션 할 수 있습니다.
이제 HandleErrorAttribute가 어떻게 사용자를 기본 Error.cshtml보기로 리디렉션하는지 확인할 수 있습니다. 아래와 같이 테스트하려면, 로그인 컨트롤러의 색인 작업에서 예외가 발생 할 수 있습니다 : 우리는 올바른 500을 반환하는 기본 MVC 프로젝트의 공유 폴더에 Errors.cshtml에서 기본 출력이 표시됩니다
public ActionResult Index() {
throw new ApplicationException("Error");
//return View();
}
상태 메시지가 있지만 스택 추적은 어디에 있습니까 ?? 이제 아래와 같이
, 우리는 Error.cshtml에 수정의 몇 할 필요가 스택 추적을 캡처 :
@model System.Web.Mvc.HandleErrorInfo
<hgroup>
<div class="container">
<h1 class="row btn-danger">Error.</h1>
@{
if (Request.IsLocal)
{
if (@Model != null && @Model.Exception != null)
{
<div class="well row">
<h4> Controller: @Model.ControllerName</h4>
<h4> Action: @Model.ActionName</h4>
<h4> Exception: @Model.Exception.Message</h4>
<h5>
Stack Trace: @Model.Exception.StackTrace
</h5>
</div>
}
else
{
<h4>Exception is Null</h4>
}
}
else
{
<div class="well row">
<h4>An unexpected error occurred on our website. The website administrator has been notified.</h4>
<br />
<h5>For any further help please visit <a href="http://abcd.com/"> here</a>. You can also email us anytime at [email protected] or call us at (xxx) xxx-xxxx.</h5>
</div>
}
}
</div>
</hgroup>
이 변화는 우리가 자세한 스택 추적을 볼 수 있는지 확인합니다.
이 방법을 시도해보십시오.
시도해주세요. http://stackoverflow.com/questions/25844627/custom-error-page-when-http-error-occured-without-changing-url/25844739#25844739 –
@HirenKagrana Tried. 나를 위해 일하지 않습니다. 500을 받고 응용 프로그램이 시작되지 않습니다. 또한 리디렉션과 같은 특정 요구 사항이 없습니다. 난 그냥 사용자 정의 오류 페이지를 원한다. – Maxsteel