Solved

ASP.NET - What page did I come from?

Posted on 2010-08-19
5
590 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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…

707 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