Solved

ASP.NET - What page did I come from?

Posted on 2010-08-19
5
580 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:josephdaviskcrm
  • 2
  • 2
5 Comments
 

Expert Comment

by:forgsk
ID: 33479852
try using the below statement
Request.ServerVariables("HTTP_REFERER")
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33479951
You are right - window.open does not pass through the referer, nor does window.location, since that is a hard jump to anywhere.
Your best bet is when using either of these to pass through the referring URL as a GET parameter.

Either that or some banks I know just track the "previous" page requested in the session state and take that as the referer.
0
 

Author Comment

by:josephdaviskcrm
ID: 33480292
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
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 500 total points
ID: 33480403
You should really be using URL encoding (Server.UrlEncode)
The URL would turn up as

http://www.xyz.com/otherpage.aspx?ReturnTo=/firstpage.aspx%3Fid=123%26otherparam=1
0
 

Author Closing Comment

by:josephdaviskcrm
ID: 33480483
Thanks
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML - Color not displaying correctly in EMAIL. 6 41
Question about JQuery and asp.net 3 27
No Data for DropDown List 2 26
How come this regular expression allows "e"? 14 38
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question