0
私は簡単な質問があります。 HTTP状態コードでコントローラからカスタムエラーページにリダイレクトするには?たとえば :ASP MVCからコントローラのエラーページにリダイレクト
public ActionResult Index()
{
this.Redirect("Not found", 404); //redirect to my error page with code 404
}
私は簡単な質問があります。 HTTP状態コードでコントローラからカスタムエラーページにリダイレクトするには?たとえば :ASP MVCからコントローラのエラーページにリダイレクト
public ActionResult Index()
{
this.Redirect("Not found", 404); //redirect to my error page with code 404
}
web.configファイルでこのコードを追加します -
<system.web>
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
をコントローラにコードの下に追加します。
public class ErrorController : Controller{
public ViewResult Index()
{
return View("Error");
}
public ViewResult NotFound()
{
Response.StatusCode = 404; //you may want to set this to 200
return View("NotFound");
}}
だけビューを返し、 戻るビュー( "ビュー名"); – Balu
'新しいHttpNotFoundResult()'を返し、組み込みのエラー処理を使用します。 –