title: MVC3 routing for any url
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc">How can I properly handle 404 in ASP.NET MVC?</a>  </p>
  </blockquote>
  
  
  
  <p>Suppose I have a site www.microsoft.com</p>
  
  <p>And I try to open the url </p>
  
  <pre><code>www.microsoft.com/anytext
  www.microsoft.com/anytext/anynumber
  www.microsoft.com/anytext/anynumber/anything
  </code></pre>
  
  <p>So how to catch these kinds of urls and show a PageNotFound partial view or view</p>
  
  <p>Let me know if you need more detail</p>
  
  <p>Here is my routings:</p>
  
  <pre><code>routes.MapRoute("PrivacyAction", "Privacy", new { controller = "Home", action = "Privacy" });
  routes.MapRoute("LegalAction", "Legal", new { controller = "Home", action = "Legal" });
  routes.MapRoute("AboutUs", "AboutUs", new { controller = "Home", action = "AboutUs" });
  routes.MapRoute("Advertising", "Advertising", new { controller = "Home", action = "Advertising" });
  routes.MapRoute("Contact", "Contact", new { controller = "Home", action = "Contact" });
  routes.MapRoute("Reputation", "Reputation", new { controller = "Home", action = "Reputation" });
  
  routes.MapRoute(
    "Users", // Route name
    "{controller}/{action}/{id}/{slug}", // URL with parameters
    new { controller = "User", action = "List", id = UrlParameter.Optional, slug = UrlParameter.Optional }); // Parameter defaults
  
  routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
  
  routes.MapRoute("Error", "{*url}", new { controller = "Error", action = "404" });
  </code></pre>
  
  <p>getting error:</p>
  
  <p>The controller for path '/anytext' was not found or does not implement IController.</p>
  
  <p>Stack Track:</p>
  
  <pre><code>at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
     at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
     at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController&amp; controller, IControllerFactory&amp; factory)
     at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClass6.&lt;BeginProcessRequest&gt;b__2()
     at System.Web.Mvc.SecurityUtil.&lt;&gt;c__DisplayClassb`1.&lt;ProcessInApplicationTrust&gt;b__a()
     at System.Web.Mvc.SecurityUtil.&lt;GetCallInAppTrustThunk&gt;b__0(Action f)
     at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
     at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1 func)
     at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
     at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
     at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>