Solved

ASP.NET - What page did I come from?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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