Handle Invalid URL in MVC
问题 How to handle invalid URLs in MVC? For ex.: When the user enters http://localhost/User/MyProfile instead of http://localhost/User/Profile, it will throw an exception. How to handle this request? 回答1: You need first to add a custom Error page url in the web.config: <customErrors mode="On" defaultRedirect="~/Error/404" /> And add a controller to handle the invalid urls: public class ErrorController:Controller { [ActionName("404")] public ActionResult Error404() { return View("Error"); } } And