1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How do you get previous page URL?

How do you get previous page URL?

8 posts, 0 answered
  1. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    08 Jul 2009
    Link to this post
    Hi all,

    I am trying to get the URL of the last page. I found this object:

    this.Page.PreviousPage 

    But it does not have any URL properties. I then tried this:

    manager = new CmsManager(); 
    IPage previous = manager.GetPage(new Guid(this.Page.PreviousPage.UniqueID)); 

    But that one doesn't have an URL properties either. Should I just use this:

    Request.UrlReferrer.ToString(); 

    Or is there something else I can do, maybe that sitefinity can do?

    Thanks!
    anders
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    08 Jul 2009
    Link to this post
    Hello andersleet,

    Before we move forward with the discussion, please let me know if using javascript is feasible for your scenario:
    javascript:history.go(-1)  

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    08 Jul 2009
    Link to this post
    I would prefer not to use javascript if it is possible.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Jul 2009
    Link to this post
    Hello andersleet,

    You could try using the following approach

    int previousIndex = this.selectedPage - 1; 
    hyperLink.NavigateUrl = GetPageUrl(previousIndex) 
     
     
     .... 
        ..... 
    private int selectedPage; 

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    09 Jul 2009
    Link to this post
    Thanks for the code Ivan,

    What namespace is the GetPageUrl in? And does anything need to be assigned to the selectedPage integer that is declared or is it some sort of special name that SF automagically adds data to?

    Thanks!
    anders
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jul 2009
    Link to this post
    Hi andersleet,

    There is no namespace it is a custom method

     private string GetPageUrl(int index) 
     { 
                StringBuilder builder = new StringBuilder(); 
     
                string currentUrl = string.Empty; 
     
                if (CmsContext.CurrentUrl != null
                { 
                     builder.Append(CmsContext.CurrentUrl.Path); 
                } 
     } 

    Another good approach can be found at asp.net forums.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. andersleet
    andersleet avatar
    155 posts
    Registered:
    03 Jun 2009
    13 Jul 2009
    Link to this post
    Hey Ivan,

    Thanks for the code and the link.  With your code, I am unable to navigate backwards. It just returns the current page that I am on. In your code, it looks like the index integer is not being used? Is there anything else I am missing to get this to work I would prefer to use your method since it utilizes the SF framework even though I have had success with the Request.UrlReferrer method.

    Cheers,
    anders
  8. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    16 Jul 2009
    Link to this post
    Hello andersleet,

    You can try this:
    protected void Page_Load(object sender, EventArgs e)  
        {  
            var prevPage = Request.ServerVariables["HTTP_REFERER"];  
        } 
    The problem with this approach is that every time you make a request from the Browser navigation bar it will return null(since there is no referer), but if you are browsing within the application it should return the correct URL. For any other scenarios, you should use the javascript approach sent in the first response.

    Regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
8 posts, 0 answered