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

Forums / Developing with Sitefinity / Programmatic Redirect

Programmatic Redirect

10 posts, 1 answered
  1. George
    George avatar
    17 posts
    Registered:
    16 Jan 2014
    23 Sep 2014
    Link to this post

    In reviewing this blog post, http://www.sitefinity.com/blogs/stefani-tacheva-s-blog/2014/03/11/redirect-unauthorized-users-to-a-custom-page, I was able to implement the code, but what I've run into is a UX issue.  I want to programmatically pick which page a user is going to after the login event, so when I redirect them to my custom login page, how can I pass along the page they were trying to access and then use that page to redirect the user later?  Do I need to create a custom control for this?

     

    Thanks!

    G

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    26 Sep 2014
    Link to this post
    Hello George,

    You can use
    Context.Request.UrlReferrer returns the absolute url of the previous page where the user has clicked the link or the button redirecting to the current page. By UrlReferrer you can see the page where the request has originated.

    If 
    UrlReferrer is null, this means that the user has directly accessed the current page, for example:
    protected override void OnLoad(EventArgs e)
    {
        // the url of the previous page
        var previousRequestUrl = Context.Request.UrlReferrer;
     
        // if the url of the previous page is not null => cross page postback
        if (previousRequestUrl != null)         
        {
         
        }
    }

    More information could be found in that article.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. George
    George avatar
    17 posts
    Registered:
    16 Jan 2014
    02 Oct 2014
    Link to this post

    Hi Svetoslav,

     I realize I can get to it in my redirect event, the problem is how do I pass that to the Login Widget?  My case looks like this to start:

    01.void OnUnauthorizedAccess(IUnauthorizedPageAccessEvent unauthorizedEvent)
    02. 
    03.{
    04.    var url = unauthorizedEvent.Page.Url.TrimStart('~');
    05.  
    06.    //for this specific page redirect to CustomerLoginPage
    07.    if (unauthorizedEvent.Page.IsBackend == false)
    08.    {
    09.        if (UserHelper.IsUserLoggedIn())
    10.        {
    11.            unauthorizedEvent.HttpContext.Response.Redirect("~/unauthorized");
    12.        }
    13.        else
    14.        {
    15.            unauthorizedEvent.HttpContext.Response.Redirect("~/login");
    16.        }
    17.    }
    18.  
    19.    //for all other pages redirect to the Sitefinity login page
    20.    //if you do not use the else clause you will be redirected to the Sitefinity login page in all other cases different that the above one
    21.    else
    22.        unauthorizedEvent.HttpContext.Response.Redirect("~/sitefinity");
    23.}
     

    Then how do I  pass that to the line 16 Login redirect so that the standard login widget will accept the URL parameter or Post Parameter for that matter?  I've tried passing it several different ways and none are picked up by the login to go to the page they were coming from.

     

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    03 Oct 2014
    Link to this post
    Hello George,

    You could try to pas the page you are cumming from and redirect as query string parameter.

    Thus you could get it in your login page and redirect back once the user is logged in.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. George
    George avatar
    17 posts
    Registered:
    16 Jan 2014
    03 Oct 2014 in reply to Svetoslav Manchev
    Link to this post

    That's what I'd like to do, but what parameter do I pass to the page where my login is?

     eg.  Login is on page ("~/login") and I pass ("~/login?gobackto=~/pageyouwanted") what is the gobackto?

  6. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    08 Oct 2014
    Link to this post
    Hello George,

    On the /Login page you probably have on Login button click method where you authenticating the user. So you need after that to get the value of the "gobackto" and to redirect to that page. 

    The "gobackto" parameter should be the page url that you are coming from and need to go back after the successful authentication.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  7. George
    George avatar
    17 posts
    Registered:
    16 Jan 2014
    14 Oct 2014 in reply to Svetoslav Manchev
    Link to this post

    Hi Svetoslav,

     I was using the built in Sitefinity Widget - so basically the current default Widget can only be set to go to a page, there's no parameter I can supply it to go back to where they came from, unless I roll my own?

     Thanks,

    George

  8. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    14 Oct 2014 in reply to George
    Link to this post

    Normally you can use the "ReturnUrl" parameter to define the page it should return to once they authenticate.

    Answered
  9. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    14 Oct 2014
    Link to this post

    Yeah ReturnUrl is the querystring is uses...but that should all work native out of the box.

     What I normally do is create my login link through code to always append the ReturnUrl=<currentpage> querystring to it.  So from anywhere in the side they click that, go to my login page, and sitefinity sends them back to where they were in a logged in state.

  10. George
    George avatar
    17 posts
    Registered:
    16 Jan 2014
    15 Oct 2014
    Link to this post

    That did it - ReturnURL was the trick.

10 posts, 1 answered