Solved

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

Posted on 2008-10-17
4
1,151 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
ID: 22745483
Request.UrlReferrer.ToString();
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22745531
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
ID: 22746308
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
ID: 22747907
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Resolve Dependency Issues 4 41
Two different visual studio versions 3 21
Angular JS Route 3 45
How to make a GridView cell hyperlinked using C# ? 3 0
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 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

17 Experts available now in Live!

Get 1:1 Help Now