Link to home
Start Free TrialLog in
Avatar of josephdaviskcrm
josephdaviskcrmFlag for United States of America

asked on

ASP.NET - What page did I come from?

In an ASP.NET application (C#)
I'm working with a site map bread crumb control that needs to have the last page in the trail be a link back to that page.  I've been trying to accomplish that so far by using Request.UrlReferrer.  This works fine under normal circumstances, but I'm worried about it failing in other circumstances.

For instance, when I come to a page with this control on it by using javascript window.loacation = "path"; the urlReferrer is null.  I've thought about trying some work around where I add an anchor element to the page using the javascript and then force a click event on that anchor, but I would rather not have to write such sloppy code like that if I can avoid it.

Are there any best practices that should be implemented in a situation like this to help a page know where the user was coming from before they came to that page?

Thanks
Avatar of forgsk
forgsk

try using the below statement
Request.ServerVariables("HTTP_REFERER")
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of josephdaviskcrm

ASKER

what do I do in situations where the return url has a query string of its own?

So if I came from http://www.xyz.com/firstpage.aspx?id=123

The path that I would set for the page would be
http://www.xyz.com/otherpage.aspx?ReturnTo=/firstpage.aspx?id=123

So there are now two '?' in my url
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks