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

Forums / General Discussions / How can one redirect after login?

How can one redirect after login?

7 posts, 0 answered
  1. Jonathan
    Jonathan avatar
    2 posts
    Registered:
    09 Jul 2012
    09 Aug 2012
    Link to this post
    I created multiple protected pages where I require the user to be logged in.  Much to my dismay, I realized that rather than allowing an unauthenticated user to login, Sitefinity throws a server error.  I've added some code to the Default.aspx which catches the error and redirects to a login page I created using the standard login control.  My current problem is that once a user logs in using the login page, they just sit there on the same page.  I'd like them returned to the protected page they came from, and I pass that to the login page as a parameter, but is there any way I can modify the login control to redirect the user back to the original page?

    Thanks,
    Jonathan
  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    14 Aug 2012
    Link to this post
    Hi Jonathan,

    Thank you for contacting us.

    Can you please let me know if you are using Claims or Forms Authentication. You can easily check that when you log in to the backend of your project. Go to Administration->Settings locate and click on User Authentication - See attached Authentication.png. 

    Thank you for your time and cooperation. 

    Greetings,
    Pavel Benov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. EJ
    EJ avatar
    6 posts
    Registered:
    07 Jun 2011
    14 Aug 2012
    Link to this post
    I've been working on this as well.   I've got claims authentication running and have used the log in widget that is not backwards compatible.  I'm also using a custom 403 to redirect to www.mysite.com/login, which is the page I built to put the login widget on.  


  4. EJ
    EJ avatar
    6 posts
    Registered:
    07 Jun 2011
    15 Aug 2012
    Link to this post
    Just a quick update:

    In 5.0, using claims authentication, I was able to get a custom log in page to come up by using the custom error page property of the web.config 

    <customErrors mode="RemoteOnly">
       <error statusCode="403" redirect="~/login" />
    </customErrors>

    It would not, however, redirect.   After some further reading, I found that this issue was fixed in 5.1, so I upgraded my sites last night to the latest release.   

    Now when I try to go to a protected page, the default log in page comes up (ie the same that comes up when I try to access the back end).  That being said it does redirect to the correct page after log in.  

    So, kind of a win?  I think?
  5. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    17 Aug 2012
    Link to this post
    Hi guys,

    One way to redirect unauthenticated users to a custom login page is to use a custom control on the forbidden pages (better solution will be to use a template and just assign that template for all forbidden pages) which will check if user is authenticated and redirect him to custom login page if not. 

    For the redirecting after login to the previously requested page you may use custom login control which should inherit from the LoginWidget class.

    In the attached .rar file you will find both the authentication checker and the custom login control. Drop the in your project and set the Build Action for the LoginCustomTemplate.ascx to Embedded Resource in Visual Studio and Build the project. 

    Register the authentication widget by going to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->Choose or create section->Tools and click CreateNew. In the Control CLR Type or Virtual Path write the virtual path to the control (e.g. ~/folder/folder/AuthCheck.ascx).

    To register the login widget follow the steps above, but in its Control CLR Type or Virtual Path type SitefinityWebApp.LoginCustom.

    Now what is left is to register the LoginCustomTemplate.ascx. To do that go to Administration->Settings->Advanced->VirtualPathSettings->VirtualPaths, click on CreateNew and fill it as shown in the attached image.

    If you use a page template to drop your Authentication widget, be sure to use another template for the Login page on which you will drop the custom Login widget.

    Kind regards,
    Pavel Benov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  6. David Whritenour
    David Whritenour avatar
    22 posts
    Registered:
    30 Nov 2009
    03 Sep 2012
    Link to this post
    Pavel,

    As of Sitefinity Version 5.1.3270.0, the following code in the web.config will no longer redirect the user to a custom login page.

    <customErrors mode="RemoteOnly">
       <error statusCode="403" redirect="~/login" />
    </customErrors>

    I attempted the solution you suggested above (using a custom widget with redirect code) but that does not work either.  It still redirects to Sitefinity's main login screen.  Any ideas what to do?

    Oh, I am using Claims Based Authentication.

    Regards,
    David
  7. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    05 Sep 2012
    Link to this post
    Hello David,

    The most probable reason that this is happening is that you may have explicitly denied view permissions to pages. This makes Sitefinity check if the user is authenticated and redirects him to the main login screen and so the code in the AuthCheck user control (that redirects to custom login page) is not even hit. 
    If that is the case go to Pages->Permissions for all pages and in the View pages section uncheck the Explicitly deny this to selected roles and users.. Or if you have set it for individual page click on the respective page's Actions menu and choose Permissions.

    All the best,
    Pavel Benov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
7 posts, 0 answered