假设我有一个网站 www.microsoft.com
我尝试打开网址
www.microsoft.com/anytext
www.microsoft.com/anytext/anynumber
www.microsoft.com/anytext/anynumber/anything
那么如何捕获这些类型的 url 并显示 PageNotFound 部分视图或视图
如果您需要更多详细信息,请告诉我
这是我的路线:
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" });
收到错误:
找不到路径“/anytext”的控制器或未实现 IController。
堆栈轨道:
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& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<BeginProcessRequest>b__2()
at System.Web.Mvc.SecurityUtil.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a()
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>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& completedSynchronously)