Solved

ASP.NET - What page did I come from?

Posted on 2010-08-19
5
572 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now