{"id":2526,"date":"2022-08-30T15:25:36","date_gmt":"2022-08-30T15:25:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/28\/problem-about-asp-net-mvc-routing-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:36","modified_gmt":"2022-08-30T15:25:36","slug":"problem-about-asp-net-mvc-routing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-asp-net-mvc-routing-collection-of-common-programming-errors\/","title":{"rendered":"problem about asp.net-mvc-routing-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/204fa96c196691d901ecd8f7d95fc356?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRyan Sampson<br \/>\nasp.net-mvc asp.net-mvc-routing<br \/>\nI have custom error pages setup using&lt;customErrors mode=&#8221;On&#8221; defaultRedirect=&#8221;~\/Home\/Error&#8221;&gt;&lt;error statusCode=&#8221;404&#8243; redirect=&#8221;~\/Home\/PageNotFound&#8221; \/&gt;&lt;\/customErrors&gt;I created a page that throws and exception and I get redirected to the correct error pages.However I am noticing these errors in elmah on the production webserver: System.InvalidOperationException The view &#8216;Error&#8217; or its master was not found or no view engine supports the searched locations. The following locations w<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/096ba6aa9a0170416fd018470309b733?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nDisplay<br \/>\nasp.net-mvc-4 asp.net-mvc-routing<br \/>\nI tried to write custom routes.Always i have 404 error what is wrong.I read about routing and did not figure out. I want to display contents like below codes and name must be between a-Z and 0-9.Thanks.{action}\/{name} \/details\/kll219dklroutes.MapRoute(name: &#8220;Default&#8221;,url: &#8220;{controller}\/{action}\/{id}&#8221;,defaults: new { controller = &#8220;home&#8221;, action = &#8220;index&#8221;, id = UrlParameter.Optional });routes.MapRoute(name: &#8220;test&#8221;,url: &#8220;details\/{name}&#8221;,defaults: new { controller = &#8220;Test&#8221;, action = &#8220;Details&#8221;, name<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/070eadc4cc8e62b858360c78d9565cd6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nValamas &#8211; AUS<br \/>\nmvc asp.net-mvc-3 asp.net-mvc-routing<br \/>\nI am using a third party nuget called AttributeRouting which registeres routes using attributes. I have a unique situation and i need to remove a route from the route table on Application_Start or similar. How can this be done?I have supplied a screenshot of the route i want to remove. I have even named it &#8220;RemoveMePlease&#8221;.thanks<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/efc074bd29356934efd9ad367bf3932f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nA.R.<br \/>\nc# asp.net-mvc-4 asp.net-mvc-routing<br \/>\nIs there a way to get MVC4 to call different actions based on a GET variable in the URL?For example, let&#8217;s say I have the following two actions.[HttpPost] public ActionResult SubmitCrash(CrashReport rawData) {return View(); }[HttpPost] public ActionResult SubmitBug(BugReport data) {return View(); }Is there a way I can use the following URLs to have MVC4 &#8216;choose&#8217; which action to call?http:\/\/MySite\/Submit?Crash (calls &#8216;SubmitCrash&#8217;) http:\/\/MySite\/Submit?Bug (calls &#8216;SubmitBug&#8217;)UPDATE: I am very m<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/556d306c992b8b47b605965a0033643e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMaritim<br \/>\nasp.net-mvc-4 iis-7.5 asp.net-mvc-routing<br \/>\nI&#8217;m using routing in my ASP.NET MVC 4 application and I&#8217;m experiencing a very strange problem. I am attempting to establish a route to an area named Ekstranett, but if I use Ekstranett as the first URL parameter I get an Internal Server Error. I can use any word except for Ekstranett and I find that very strange. This is my setup:context.MapRoute(&#8220;Exception&#8221;,&#8221;Ekstranett\/Exception\/{action}\/{*handle}&#8221;,new { controller = &#8220;Exception&#8221;, action = &#8220;General&#8221;, handle = UrlParameter.Optional },new[] { &#8220;MyP<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/25587d7aa1b58792968c1a07514635bb?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMalcolm Frexner<br \/>\nasp.net-mvc iis7 asp.net-mvc-routing<br \/>\nI use a simple ASP.NET MVC web (the template you use when you create a new site) and the web works as expected in my live environment.I now try to use IIS Application Request Routing version 2. I have a rule that send all reuqests to a different server that match a rule.The settings are a bit like this: http:\/\/blogs.iis.net\/wonyoo\/archive\/2008\/07\/09\/application-request-routing-arr-as-a-reverse-proxy.aspxMy rule is just a bit different it is \/shop(.*). Only requests that contain shop are send to<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nasp.net-mvc asp.net-mvc-routing<br \/>\nI&#8217;ve searched the internet high and low and checked all previously answered questions with the same title and I cannot figure this one out. I return RedirectToAction(&#8220;Index&#8221;, &#8220;Home&#8221;) from the action method in my authentication controller and then receive the following exception:Server Error in &#8216;\/&#8217; Application. The controller for path &#8216;\/Home&#8217; was not found or does not implement IController. Description: An unhandled exception occurred during the execution of the current web request. Please revie<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nasp.net-mvc asp.net-mvc-routing<br \/>\nI have currently the following routes:routes.IgnoreRoute(&#8220;{resource}.axd\/{*pathInfo}&#8221;);routes.IgnoreRoute(&#8220;{resource}.gif\/{*pathInfo}&#8221;);MvcRoute.MappUrl(&#8220;{controller}\/{action}\/{ID}&#8221;).WithDefaults(new { controller = &#8220;home&#8221;, action = &#8220;index&#8221;, ID = 0 }).WithConstraints(new { controller = &#8220;&#8230;&#8221; }).AddWithName(&#8220;default&#8221;, routes).RouteHandler = new MvcRouteHandler();MvcRoute.MappUrl(&#8220;{title}\/{ID}&#8221;).WithDefaults(new { controller = &#8220;special&#8221;, action = &#8220;Index&#8221; }).AddWithName(&#8220;view&#8221;, routes).RouteHandler<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nc# asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing<br \/>\nI want to catch the latest unhandled error application and redirect it to error page whenever error has occurred. But I got error &#8220;No matching route found for RedirectToRoute.&#8221; What&#8217;s the problem with my code? Here&#8217;s my implementation:Global.asaxroutes.MapRoute(&#8220;ErrorHandler&#8221;,&#8221;{ErrorHandler}\/{action}\/{errMsg}&#8221;,new {controller=&#8221;ErrorHandler&#8221;, action = &#8220;Index&#8221;, errMsg = UrlParameter.Optional });Application_Endprotected void Application_Error(object sender, EventArgs e){var strError = Server.GetLas<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5c0e1561200995a99872fff2b7fb0a30?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nataravati<br \/>\nasp.net-mvc asp.net-mvc-routing<br \/>\nI have the following controller:public class HomeController : Controller {public ActionResult Index(){return View();} }And, route:routes.MapRoute(&#8220;spa&#8221;,&#8221;{section}\/{id}&#8221;,new { controller = &#8220;Home&#8221;, action = &#8220;Index&#8221;, id = UrlParameter.Optional },new { section = @&#8221;home|questions|admin&#8221; });When I use the following, I get an error message:return RedirectToAction(&#8220;Index&#8221;, &#8220;Home&#8221;);Error message:Server Error in &#8216;\/&#8217; Application.No route in the route table matches the supplied values. Description: An unhan<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/40de750233b3ce8268f235ba0b6a489b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nteresko<br \/>\nasp.net-mvc asp.net-mvc-routing redirecttoaction redirecttoroute<br \/>\nIm Redirecting my action Using RedirectToRoute with parametes and i defined the route in global.asaxreturn RedirectToRoute(&#8220;RouteName&#8221;, new { action = &#8220;Search&#8221;, Id, Customer, Source,class,Type,Desc, Date, Loc, input, prod, effDate, remainDate });routes.MapRoute(name: &#8220;RouteName&#8221;,url: &#8220;{controller}\/{action}\/{Id}\/{Customer}\/{Source}\/{class}\/{Type}\/{Desc}\/{Date}\/{Loc}\/{input}\/{prod}\/{effdate}\/{remainDate}\/&#8221;,defaults: new{controller = &#8220;MyCOntroller&#8221;,action = &#8220;Search&#8221;,Id = UrlParameter.Optional,Custo<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f0aeac35a15cbe0c875552b4ccbe7eeb?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDavid Williams<br \/>\nasp.net-mvc asp.net-mvc-3 asp.net-mvc-routing<br \/>\nGiven the controller belowpublic class MyController : Controller {public ActionResult Index(){return View();}public ActionResult Test(){return RedirectToRoute(new { action = &#8220;Index&#8221; });}}And this routingpublic static void RegisterRoutes(RouteCollection routes) {routes.IgnoreRoute(&#8220;{resource}.axd\/{*pathInfo}&#8221;);routes.MapRoute(&#8220;Route1&#8243;,&#8221;Route1&#8221;,new {controller = &#8220;Account&#8221;, action = &#8220;Index&#8221;});routes.MapRoute(&#8220;Default&#8221;, \/\/ Route name&#8221;{controller}\/{action}\/{id}&#8221;, \/\/ URL with parametersnew { controlle<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/290dfe6633a84027524b45ed2c1ab330?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nUfuk Haciogullari<br \/>\nasp.net-mvc asp.net-mvc-routing<br \/>\nI need to ignore routes matching this schema\/{controller}\/edit\/undefined{controller} &#8211; could be any controllerBTW I was wondering when to use Ignore and when IgnoreRoute.<\/li>\n<li>\n<img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/296f29c92c1561c79e034df64dc19f56?s=128&amp;d=identicon&amp;r=PG\" \/><br \/>\nLeniel Macaferi<br \/>\nasp.net asp.net-mvc asp.net-mvc-3 error-handling asp.net-mvc-routing<br \/>\nI want to return a HTTP status 404 if invalid arguments are passed to my controller. For example if I have a controller that looks like:public ActionResult GetAccount(int id) {&#8230; }Then I want to return a 404 if say urls such as these are encountered:\/GetAccount \/GetAccount\/notanumberi.e. I want to trap the ArgumentException that is thrown.I know I could use a nullable type:public ActionResult GetAccount(int? id) {if(id == null) throw new HttpException(404, &#8220;Not found&#8221;); }But that&#8217;s pretty icky<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2014-01-28 10:03:46. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Ryan Sampson asp.net-mvc asp.net-mvc-routing I have custom error pages setup using&lt;customErrors mode=&#8221;On&#8221; defaultRedirect=&#8221;~\/Home\/Error&#8221;&gt;&lt;error statusCode=&#8221;404&#8243; redirect=&#8221;~\/Home\/PageNotFound&#8221; \/&gt;&lt;\/customErrors&gt;I created a page that throws and exception and I get redirected to the correct error pages.However I am noticing these errors in elmah on the production webserver: System.InvalidOperationException The view &#8216;Error&#8217; or its master was not found or no [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2526","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2526"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2526\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}