Page.RouteData returning WebResource.axd?

1.1k views Asked by At

I have a rule in my Global.asax like so:

RouteTable.Routes.MapPageRoute("defaultRoute", "{*value}", "~/default.aspx")

Essentially, any page that doesn't physically exist is redirected to default.aspx. When that page loads I use the following in the Page_Load sub like so:

Dim prospect_url As String = Page.RouteData.Values("value")

I then convert this into a session variable like so:

Session("prospect_url") = prospect_url

Eventually, the individual is redirected to another page...where I need to access this value again, but when I perform the following:

Dim prospect_url As String = CStr(Session("prospect_url"))

I get WebResource.axd as the value for prospect_url. What?!? Where did that come from?

2

There are 2 answers

0
BeemerGuy On BEST ANSWER

That global rule applies to any resource being requested, including image files, script files, and any other resource (such as that WebResource.axd you're seeing).
So what happened here is that your route table rule caused it to save each request into your session variable, overwriting the last value every time, and by the time you looked at the session variable yourself, it was left at WebResource.axd (it could be something else on a different instance).

I have one solution to that approach on my blog:
http://beemerguy.net/blog/post/How-to-support-dynamic-URLs-in-ASPNET-(by-example).aspx
But it's in C#, and it should be straightforward to translate into VB.NET.

But essentially, you should handle the prospect url value in the same request, not relying on the session variable, coz other simultaneous requests could overwrite that value before you get to it.

0
Shvarc On

Try code below:

 protected void Application_Start(object sender, EventArgs e)
 {
     RegisterRoutes(RouteTable.Routes);

     ...
 }

 private static void RegisterRoutes(RouteCollection routes)
 {
    routes.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));

    ...
 }