Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to 404 page programmatically using asp.net MVC

I have created a Asp.net MVC application. Now required 404 handling.

Have updated global.asax and display 404 page based on status code. Also added customErrors property in web.config. Its working fine.

Now I would like to redirect to 404 programmatically when any thing not match with our requirement.

i.e.

if(!valid) 
{
    return RedirectToAction("Index", "Page404");
}

It's working fine but there are 2 status one is 301 & then 404. So how can I prevent 301? I just need 404.

How can I achieve this?

like image 890
Laxmi Lal Menaria Avatar asked May 22 '12 13:05

Laxmi Lal Menaria


1 Answers

Simply return from your action:

return HttpNotFound();
like image 177
jorgehmv Avatar answered Oct 22 '22 06:10

jorgehmv