Page.GetRouteURL in WebForms displays the "length" querystring parameter

I work in a webforms application using routing in .net 4. I defined a very simple route in global.asax as follows:

RouteTable.Routes.MapPageRoute("myRouteName", "MyRoutePath", "~/RouteHandlers/MyHandler.aspx"); 

In the code block of one of my pages, I use GetRouteUrl to create a URL for this named route as follows:

  Response.RedirectPermanent(GetRouteUrl("myRouteName")); 

This does not give the expected result http://sitename/MyRoutePath . Instead, it creates http://sitename/MyRoutePath?length=15

The length parameter doesn't seem to hurt, but I spent a lot of time making the URLs look beautiful, so I don't want to see an additional parameter. Any idea how to disable it?

+8
source share
1 answer

I ran into this same problem with one of my routes using Web Forms this morning, and I circumvented it by providing a second argument to the GetRouteUrl method, passing null (since this particular route did not require any route parameters).

For example:

 GetRouteUrl("name-of-my-route", null) 

My URL is now clean and not added with length = 15.

Hope this helps your situation too.

+16
source share

All Articles