[RESOLVED] Url Routing in .net 4.0 and 3.5


    I am trying to implement Url routing in 4.0 by following example http://www.dotnetspark.com/kb/2369-step-by-step-tutorial-on-url-routing-asp-net.aspx

Works fine..

Now the scenario is that i have gridview with object datasource which accepts  "Name" as query string.

<asp:gridview ID="Gridview1" runat="server" DataSourceID="ObjectDataSource1"></asp:gridview>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            OldValuesParameterFormatString="original_{0}" SelectMethod="Hello"
                <asp:QueryStringParameter Name="value" QueryStringField="Name" Type="String" />

i tried this code. But i couldn't get the value in QueryString Field??

How to handle in this situation??


How to implement (the link example in net 3.5)??? because i don't  "


" attribute in  3.5. i have few existing application in 3.5 so thought of implementing there too.

Please guide me..This example in Link looks very easy and simple to handle


if your getting the value parameter from a pageroute you cant use querystring you should use a Route Parameter something like this.

<asp:RouteParameter RouteKey="Name" Name="value" Type="String" />

here you have another example how to do it... http://weblogs.asp.net/hajan/archive/2010/10/15/url-routing-in-asp-net-4-0-web-forms.aspx

In his example he is showing a codebehind example of how to access the route but in my example show you how to use it...

Hope it helps....

So you mean to say that i can't use querystring for passing value to objectsource???

How to pass the value objectsource then???

In your link you have shown it in asp.net 3.5 sp1. right??

But how to pass value on click of the Button? like he has shown in the example (mine link).

because in my scenario i have to pass value through querystring in many places...so before i implement this feature i need to know how to access the value in pass it in objectdatasource and i don't want to use code behind.

i just checked on net http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Is the

<asp:routeparameter name="category" RouteKey="category" />

not available for 3.5 sp1 in webforms???


Im not sure if it works in 3.5 I upgraded all my apps to 4.0 when implementing routing. 

If you use url routing the routeparameter replaces querystring. the querystring fetches the parameter after the questionmark (?) in the url and when using routing you dont have it. 


i could see few example with routing stuff in asp.net 3.5 but i am not able to get  <asp:routeparameter in my html.

indeed this is why I choose to wait with moving from URL rewrite to URL routing until I moved to ASP.NET 4.0 even finding answers for URL Routing 4.0 is difficult if your not working with MVC and want some info covering more than the basic's

this works with ASP.NET 4.0 but if the <asp:routeparameter is not supported in asp.net 3.5 I can only see that you have to declare it in codebehind if you want it to work with you SqlDataSource.


ok i made one small application in 4.0 now and implemented Url routing in that and hosted in IIS in my machine (win 7).

but i get an error

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

now what could be the reason...when i am running with my visual studio then it works fine but when i hosted in IIS then i landed in above problem.

code i use.

protected void Application_Start(object sender, EventArgs e)

   void CustomRouteTable(RouteCollection routes)

            routes.MapPageRoute("Telugu", "Movie/Telugu", "~/Telugu/Telugu.aspx");

and in my default.aspx i kept a button on click of the button i wrote:

 protected void btnTelugu_Click(object sender, ImageClickEventArgs e)

now where am i going wrong????

please guide me...



HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.


It seems that IIS can not handle the UrlRoute when you enter the route url in browser.

I think you need to check the .NET framework version of the web site application pool. Url Route module need .NET 3.5 or upon.

Open the IIS manager and check it.

How to check the .NET version on IIS7:



Or add the UrlRoutingModule in web.config:

Check this link:


Hope this can help you.

Well do you have a file with the path ~/telugu/telugu.aspx because that is what you pointing at!

my guess would be that not...

 routes.MapPageRoute("Telugu", _ //routename

"Movie/Telugu", _  // you have hardcoded a virtual path and it is not expecting any paramenters parameter should be within {}

"~/Telugu/Telugu.aspx"); // this is the physical path...


let say you hav a file Movie.aspx in your root folder and you want to have a url that is movie / title .aspx it the route you should register is like this


and then for the url to redirect correctly with a given parameter it should be something like this  

RedirectToAction("title", "Movie"); // Action, Controller
RedirectToRoute("MovieRoute"); // Route name or like this if it is to a route without a parameter

hope it helped a little

thoughts on "[RESOLVED] Url Routing in .net 4.0 and 3.5 "

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>