Skip to content

How to redirect to error page in view?

July 4, 2011

Recently I made a forum answer post to how you can redirect to a customised error page in ASP NET MVC 2 for error pages?

Here is the answer: –

<customErrorsmode=”On”defaultRedirect=”CustomErrorView” >
<errorstatusCode=”404″redirect=”Error/Error404″ />
<errorstatusCode=”500″redirect=”Error/Error500″ />
< /customErrors>

The controller:

public class ErrorController : Controller
{
// Return the 404 not found page
public ActionResult Error404()
{
return View();
}

// Return the 500 not found page
public ActionResult Error500()
{
return View();
}
}

This could be done with a static page if needed:

<customErrorsmode=”On” >
<errorstatusCode=”404″redirect=”Static404.html” />
< /customErrors>

The link to the forum post is http://forums.asp.net/t/1693685.aspx/1?How+to+redirect+to+error+page+in+view+

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: