Solved

How to get the name of the calling page in ASP.NET?

Posted on 2008-10-17
4
1,150 Views
Last Modified: 2010-05-18
Hello - I have a "list" page, that works in conjunction with a "detail" page; the detail page has a link on it to "Return to list", with the following code executed on the Click:
      Response.Redirect("~/ProjectsList.aspx")

Now I have been asked to provide a second version of the list page; a given user will be using one or the other, depending on their access rights. (I am not using ASP.NET's navigation features; I did my own user access control.)

So now, from the detail page, I need to return to the version of the list page that they came from.

Can someone tell me the syntax (in ASP.NET v2.0, VB.NET) to test the name of the previous page? So I can do something like:

      If {calling page name = "ProjectsList1.aspx"} then
            Response.Redirect("~/ProjectsList1.aspx")
      Else
            Response.Redirect("~/ProjectsList2.aspx")
      End If      

Unless there is a smarter way to do this?

Thanks

0
Comment
Question by:mlagrange
4 Comments
 
LVL 6

Expert Comment

by:pwrBall
Comment Utility
Request.UrlReferrer.ToString();
0
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
You can try "Request.UrlReferrer" - this will give the url of the previous page

I am not sure if you would be able to get the name of the file.in below approach
but you can get the reference to the page that redirected to the current page from the property "PreviousPage"
eg.
PreviousPage.Form.Name will give you the name of the form in previous page

take a look at the properties available in "PreviousPage" and use the one suitable for you.


0
 
LVL 3

Accepted Solution

by:
JunkMan earned 500 total points
Comment Utility
There are some issues with using HTTPReferer, some firewalls/antivirus block it from being sent. Thus you might have the odd user that is not able to return to the list. If you don't mind that the solution provided by TechTiger007 or pwrBall should work fine. But if you do I would suggest just sending the url of the list to the detail page and redirect back from that.
<a href="mydetailpage.aspx?ret_url=<%= Server.UrlEncode(Request.RawUrl) %>">view detail</a>
 

//and your return link would look like
 
 

<a href="<%= Server.UrlDecode(Request.QueryString["ret_url"]) %>">Return to list</a>

Open in new window

0
 

Author Comment

by:mlagrange
Comment Utility
pwrBall - I checked the value in Request.UrlReferrer in the debugger; it was the detail page name

TechTiger007 - PreviousPage had no values in it at all

I think JunkMan's answer is the most practical for what I need at the moment

Thank you all for your responses
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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

10 Experts available now in Live!

Get 1:1 Help Now