ashish
ashish

Reputation: 25

asp.net mvc 5 handle unknow controller name from url

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

Answers (2)

Ravikumar
Ravikumar

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

Ortund
Ortund

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

Related Questions