Solved

ASP.NET - What page did I come from?

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Undefined Index in HTML Form? 2 32
Javascript Hashmap output 8 46
Bad <form> statement? 9 25
two div layout one vertical other horizontal. 5 6
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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 learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

22 Experts available now in Live!

Get 1:1 Help Now