Search code examples
asp.netroutesasp.net-4.0webformsasp.net-routing

Asp.net 4.0 Routing , accessing querystring in Web Forms


I have an existing Asp.net 4.0 web form application which has used Asp.net routing 4.0. Now, I have to add a route to my web form application. But i cant figure out how to access the querystring to my aspx page.

What i did is,

routes.MapPageRoute("Products","Products/","~/WebPages/Products.aspx?pid=4",false)

After adding that piece of code what i expected was that, when i browse http:\localhost\mysite\Products i should be redirected to my Products.aspx page and there I should be able to access the Request.QueryString["pid"]. But I am not able to access the querystring.

I doubt whether this is allowed in Asp.net 4.0 Routing for Webforms. How can i fulfill my requirement?

Thanks, M


Solution

  • Something like:

     routes.MapPageRoute("ProductssRoute",
        "Products/{*queryvalues}", "~/Products.aspx",
        false,
        new RouteValueDictionary 
            { { "pid", @"\d{4}" }});
    

    See http://msdn.microsoft.com/en-us/library/cc668177.aspx