Reputation: 25
In Asp.net Mvc 5 How we can redirect another page if controller name is invalid in url like http://localhost:51056/free
Upvotes: 0
Views: 80
Reputation: 625
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
}
Upvotes: 1
Reputation: 8245
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.
Upvotes: 1