Web.config でカスタム エラーを有効に設定しました。
<customErrors mode="On"/>
そして、Application_Start に次のように入力します。
protected void Application_Error(object sender, EventArgs e) {
var ex = Server.GetLastError().GetBaseException();
var routeData = new RouteData();
if (ex.GetType() == typeof(HttpException)) {
var httpException = (HttpException)ex;
var code = httpException.GetHttpCode();
routeData.Values.Add("status", code);
} else {
routeData.Values.Add("status", -1);
}
routeData.Values.Add("action", "Index");
routeData.Values.Add("controller", "Error");
routeData.Values.Add("error", ex);
IController errorController = new Kavand.Web.Controllers.ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
また、次のようなエラー コントローラーを作成します。
public class ErrorController : Kavand.Web.Mvc.Kontroller
{
public ActionResult Index(int status, Exception error) {
Response.StatusCode = status;
HttpStatusCode statuscode = (HttpStatusCode)status;
return View(statuscode);
}
}
しかし、エラーが発生すると、カスタム ビューの代わりにイエロー ページが表示されます。誰もが私を助けてくれますか?! どうもありがとう、よろしく