Tuesday, March 13, 2012

Trouble With UrlReferrer

I'm trying to store a session variable to store the filename of the page where the user was before the current one.

The reasoning is that I'm trying to store the value so that if a users session times out, I have the redirected to the logon page. Once they've logged back in I'd like to automatically take them back to the page where they were before.

I've tried using Session("ref")=Request.UrlReferrer to store the value. To test that I have the referring page I've created a label and assigned it the value of Session("Ref") by using lblReferrer.Text=Session("ref").

At first I was just getting a nothing where I exprected to see the referrer on the page. Today it's throwing an error saying can't convert a Uri to a String.

I've had a look at the documentation for Uri's but can't see a way to get just the referrers url.

Im I going about this the wrong way, or is it something basic I've missed?

Thanks
JasonSession("ref")=Request.UrlReferrer.ToString()
I did have .ToString() in the code at some stage, but I obviously in the wrong place.

In any case, you've solved my problem. Thanks for your help.
Jason

0 comments:

Post a Comment