Redirect to 404 page programmatically using asp.net MVC
Simply return from your action:
return HttpNotFound();
Just throw out a 404 in the status code:
Response.StatusCode = (int)System.Net.HttpStatusCode.NotFound
In your web.config
, add:
<customErrors mode="On" >
<error statusCode="404" redirect="/404.shtml" />
</customErrors>
This will redirect on 404.shtml page when requested resource is not found.
Note: No need to programmatically redirect users for such situation.
EDIT: I literally suggest:
if (Context.Response.StatusCode == 404) {
// handle this
}