次のコードを使用して404エラーをエラーコントローラ\ viewにキャッチしてリダイレクトします。エラー制御装置においてなぜResponse.StatusCode =(int)HttpStatusCode.NotFoundは私に汎用エラーハンドラを与えますか?
Response.Clear();
Server.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "Error";
routeData.Values["action"] = "HttpError";
routeData.Values["exception"] = exception;
Response.StatusCode = 500;
//if http 404 redirect to http404 action
if (httpException != null)
{
Response.StatusCode = httpException.GetHttpCode();
switch (Response.StatusCode)
{
case 404:
routeData.Values["action"] = "Http404";
break;
}
}
私はResponse.StatusCodeを設定している場合=(INT)HttpStatusCode.NotFound私は一般的なエラーハンドラではなく、私が返されるビューを取得します。これは生産時にのみ発生するようです。なぜどんなアイデア?
[AllowAnonymous]
public ActionResult Http404()
{
//this line causes generic error handler
Response.StatusCode = (int)HttpStatusCode.NotFound;
var viewModel = new ErrorViewModel
{
Description = "Hmm, the page you're looking for can't be found"
};
return View("Error", viewModel);
}