9

I'm trying to add a route in my web forms application by following this:

http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application

I've added the route in my Global.asax file like so:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("", "/WebsiteName/{combinedPin}", "~/Default.aspx");
}

I then try to visit my website locally like this:

http:// localhost:12345/WebsiteName/test36u

But I get a resource cannot be found message so I don't think my route is correct. Can anybody see a problem with my code?

Any pointers would be much appreciated.

Thanks

1 Answer 1

5

You do not need to specify the name of your website as part of the route, try with this code:

routes.MapPageRoute("", "{combinedPin}", "~/Default.aspx");

With the above code, your link would look like:

http://localhost:12345/WebsiteName/test36u

If however your intention is that your users access your site using a segment named: WebsiteName then use:

routes.MapPageRoute("", "WebsiteName/{combinedPin}", "~/Default.aspx");

But in the precedent code your users will have to access your resource as follows: (probably not the expected result though)

http://localhost:12345/WebsiteName/WebsiteName/test36u
2
  • Thanks Jupaol. Would I still be able to access Request.QueryString["combinedPin"] ? I want to be able to check to see if it exists for error handling... Jul 29, 2012 at 2:43
  • 1
    Ignore me, I figured out I can get at it like this: Page.RouteData.Values["combinedPin"] Jul 29, 2012 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.