tag:blogger.com,1999:blog-1179473529409580853.post7217087610634772032..comments2024-02-02T10:16:36.942+01:00Comments on Erratic software development: Removing route values from links/URLs in Asp.net MVCRoberthttp://www.blogger.com/profile/16847404771942651365noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-1179473529409580853.post-81674512827771612552016-11-29T16:30:32.384+01:002016-11-29T16:30:32.384+01:00I have trid with the Web-form but got stuck at som...I have trid with the Web-form but got stuck at some point , can you help me out with it please?Webrusterhttps://www.blogger.com/profile/12951948172368422186noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-47061660922848635072016-11-04T00:19:55.150+01:002016-11-04T00:19:55.150+01:00I haven't used Web Forms since MVC came out an...I haven't used Web Forms since MVC came out and back then Web Forms didn't support routing. Nowadays things are different. Looking at WF routing it seems this could as well be used there albeit with few modifications. The underlaying mech of routing seems to be very similar if not identical to MVC/WebAPI.Roberthttps://www.blogger.com/profile/16847404771942651365noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-45515271640430867152016-10-30T09:53:45.674+01:002016-10-30T09:53:45.674+01:00Is this class file applicable for the web forms ro...Is this class file applicable for the web forms routing?Webrusterhttps://www.blogger.com/profile/12951948172368422186noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-18641480725728293842016-04-27T19:03:15.858+02:002016-04-27T19:03:15.858+02:00nicenice读者https://www.blogger.com/profile/02626431767492125283noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-70247082775698022842014-10-21T13:44:34.651+02:002014-10-21T13:44:34.651+02:00You're getting these invalid links because whe...You're getting these invalid links because when routing builds your links it has a match in the first route map. All your links on pages and created using either <i>@Url.Action(action, controller)</i> or <i>@Html.ActionLink(text, action, controller)</i> will always point to your first application.<br /><br /><b>Two suggestions for you</b><br />1. Have just a single route map, but provide app as a parameter <i>{app}/{controller}/{action}/{id}</i> or<br />2. Create links using named routes using <i>@Url.RouteUrl</i> where you provide route name along with parameters<br /><br />I would go with #1 because current page's app parameter would be used with link generation and you could simply use the same <i>@Url.Action(action,controller)</i> link URL generation call. but maybe there are other subtleties to your application and you should know better which of these scenarios would work better in your case.Roberthttps://www.blogger.com/profile/16847404771942651365noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-5164693255610777082014-10-16T17:19:12.117+02:002014-10-16T17:19:12.117+02:00I am building a ASP.NET MVC application. In the Ro...I am building a ASP.NET MVC application. In the RouteConfig.cs I am adding MapRoutes as follows:<br /><br />var appModel = new AppModel();<br />var apps = appModel.GetAppNames();<br />foreach (var appName in apps)<br />{<br /> routes.MapRoute(<br /> name: "application" + appName,<br /> url: appName + "/{controller}/{action}/{id}",<br /> defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }<br /> );<br />}<br />When I go to page, for example http://localhost/appName1/Dashboard I have a link on my view that points to http://localhost/appName1/Home/About.<br /><br />After that, when I go to another page - http://localhost/appName2/Dashboard, my link on my view still points to http://localhost/appName1/Home/About(and it should be http://localhost/appName2/Home/About). I am building the link with "< a href='@Url.Action("About", "Home")' >about". How to solve this?Anonymoushttps://www.blogger.com/profile/08146838504027949525noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-25180585770862515402014-09-17T14:16:43.545+02:002014-09-17T14:16:43.545+02:00You haven't given enough information about you...You haven't given enough information about your problem. Please copy how you define your routes. By the info you've given everything seems possible.<br />This particular blog post of mine solves a problem when you have several different routes with differently named route parameters. When creating routes on one route pointing to another these mismatched parameters are also being transferred across.Roberthttps://www.blogger.com/profile/16847404771942651365noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-46533017024732466922014-09-17T13:49:44.670+02:002014-09-17T13:49:44.670+02:00What about if I need a custom url of
http://www....What about if I need a custom url of <br /><br />http://www.mydomain.com.br/company/details<br /><br />to<br /><br />http://www.mydomain.com.br/company<br /><br />first question is it possible?<br />if yes, how?Gaurav Aroraahttps://www.blogger.com/profile/17624190238475460937noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-71024324149684539192013-11-15T21:15:00.191+01:002013-11-15T21:15:00.191+01:00Hi, thanks for article. Found out that (at least) ...Hi, thanks for article. Found out that (at least) in MVC 4 it's possible to do like this:<br /> 1: routes.MapRoute(<br /> 2: "CustomerSpecific",<br /> 3: "Customers/{customerId}/{controller}/{action}/{id}"<br /> 4: new { controller = "Customers", action = "Index", id = UrlParameter.Optional },<br /> 5: new { customerId = @"\d+" }<br /> 6: );<br /> 7: <br /> 8: routes.MapRoute(<br /> 9: "Default",<br /> 10: "{controller}/{action}/{id}",<br /> 11: new { controller = "Home", action = "Index", id = UrlParameter.Optional, customerId = string.Empty } //<- this prevent adding query parameter of customerId<br /> 12: );<br /><br />Now generating link with customerId = string.Empty will not add query parameter "customerId"..<br /><br />Html.ActionLink("All products", "Index", "Products", new {<br /> 12: customerId = string.Empty,<br /> 13: id = string.Empty<br /> 14: })<br /><br />-br, Alexey<br />Anonymoushttps://www.blogger.com/profile/10597679533015641634noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-40317905885495647862013-11-13T14:55:29.350+01:002013-11-13T14:55:29.350+01:00Thanks Kijana. My words at the top of this post ap...Thanks Kijana. My words at the top of this post apparently helped. And I hope content helped you as well. Roberthttps://www.blogger.com/profile/16847404771942651365noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-55994981860637157522013-11-07T21:54:10.389+01:002013-11-07T21:54:10.389+01:00Found this post with "unwanted". Thanks!...Found this post with "unwanted". Thanks!Kijana Woodardhttps://www.blogger.com/profile/15024892945339453558noreply@blogger.comtag:blogger.com,1999:blog-1179473529409580853.post-75444468380699704422011-03-30T05:43:51.776+02:002011-03-30T05:43:51.776+02:00Why not do something like the following in your Ge...Why not do something like the following in your GetVirtualPath method:<br /><br />var filteredValues = new RouteValueDictionary(values);<br /><br />foreach (var key in excludeKeys)<br />{<br /> filteredValues.Remove(key);<br />}<br /><br />return base.GetVirtualPath(requestContext, filteredValues);<br /><br />This worked for me (MVC3). Is there a real need to wrap the request?JThttp://jtnlex.com/blognoreply@blogger.com