In Asp.net Mvc 5 How we can redirect another page if controller name is invalid in url like http://localhost:51056/free
2 Answers
You can set configuration in web.config like
<customErrors mode="On" >
<error statusCode="404" redirect="/404.shtml" />
</customErrors>
or You can do this in Global.asax
if (Context.Response.StatusCode == 404) {
// handle this
}
1 Comment
Ortund
In theory you could have this redirect to a a different controller than the one requested and that would handle the 404 in a way that would allow the user to continue working on your site. So if
/free is a deprecated link that people are still somehow using (from an outdated share somewhere else maybe) then you could do this to get them to the new url. Only drawback would be that it'd work that way for EVERY 404...