In Asp.net Mvc 5 How we can redirect another page if controller name is invalid in url like http://localhost:51056/free
Asked
Active
Viewed 66 times
0

ashish
- 25
- 7
-
Check this: https://stackoverflow.com/questions/1983131/redirect-to-home-index-when-page-not-found – Sujith Jul 26 '17 at 08:00
2 Answers
1
Redirecting to a controller name that doesn't exist will always return an HTTP 404 (Not Found) response.
Probably the best way would be to set up a redirection rule on your server that redirects /free
to some other path that does exist.

Ortund
- 8,095
- 18
- 71
- 139
1
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
}

Ravikumar
- 613
- 1
- 9
- 22
-
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... – Ortund Jul 26 '17 at 08:17