Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page.GetRouteURL in WebForms outputs "length" querystring param

I'm working in a webforms app that uses routing in .net 4. I've defined a very basic route in global.asax as follows:

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

In the codebehind of one of my pages I'm using GetRouteUrl to generate a the URL for this named route as follows:

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

This doesn't produce the expected result of http://sitename/MyRoutePath. Instead it produces http://sitename/MyRoutePath?length=15

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

like image 972
John Hoge Avatar asked Mar 29 '11 21:03

John Hoge


1 Answers

I encountered this very same issue with just one of my routes using Web Forms this morning and I've got around it by providing a 2nd argument to the GetRouteUrl method, passing in null (as this particular route didn't require any route parameters).

For example:

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

My Url is now clean and is not appended with ?length=15.

Hopefully this might help your situation too.

like image 80
marcusstarnes Avatar answered Sep 30 '22 02:09

marcusstarnes