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

Forums / General Discussions / Change login page only for Front-end website

Change login page only for Front-end website

6 posts, 0 answered
  1. Nattawut
    Nattawut avatar
    16 posts
    Registered:
    14 Jul 2012
    21 Jan 2013
    Link to this post
    I am using SF version 5.2
    In the CMS, I already have a page "/login" which is a login page for front-end of the website.

    When I set a page to have a permission that only "Authenticated" role can see the content, it always redirect to the SF login page "/Sitefinity/Authenticate/SWT".

    How can I change the login page only for Front-end?
  2. Arno
    Arno avatar
    249 posts
    Registered:
    08 Sep 2010
    21 Jan 2013 in reply to Nattawut
    Link to this post
    Hi Nattawut,

    This is what support recommended me to do in global.asax and it works fine (in 5.3):

        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Fire Bootstrapper_Initialized when the Bootstrapper is initialized.
            AddHandler Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized, AddressOf Bootstrapper_Initialized
        End Sub
     
        Private Sub Bootstrapper_Initialized(sender As Object, e As Telerik.Sitefinity.Data.ExecutedEventArgs)
                ' Fire OnUnauthorizedAccess whenever a request to a page is made and the current user is not authorized to access it.
                Telerik.Sitefinity.Services.EventHub.Subscribe(Of Telerik.Sitefinity.Web.Events.IUnauthorizedPageAccessEvent)(New Telerik.Sitefinity.Services.Events.SitefinityEventHandler(Of Telerik.Sitefinity.Web.Events.IUnauthorizedPageAccessEvent)(AddressOf OnUnauthorizedAccess))
        End Sub
     
        Private Sub OnUnauthorizedAccess(unauthorizedEvent As Telerik.Sitefinity.Web.Events.IUnauthorizedPageAccessEvent)
            Try
                ' The user is not authorized to access the requested page. Redirect to the login page.
                Dim RequestedURL As String = unauthorizedEvent.Page.Url.TrimStart("~")
    ' Set LoginURL to the desired URL here, and perhaps include the RequestedURL if desired.
                Dim LoginURL As String
     
                unauthorizedEvent.HttpContext.Response.Redirect(LoginURL)
        End Sub
  3. Nattawut
    Nattawut avatar
    16 posts
    Registered:
    14 Jul 2012
    29 Jan 2013 in reply to Arno
    Link to this post

    Hi Arno,

    Thank you very much. It works as expected. ;)

    Nattawut

  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    02 Feb 2013 in reply to Arno
    Link to this post
    @Arno,
      If you type in /Sitefinity/Pages (for example, not logged in)...does this trigger for you?
  5. Arno
    Arno avatar
    249 posts
    Registered:
    08 Sep 2010
    02 Feb 2013 in reply to Steve
    Link to this post
    Hi Steve,

    No, it does not trigger when using your example URL. This method only works for frontend pages. It works if I type https://localhost/account, which is one of my secured frontend pages. I'm not sure if there's a way to force a custom login page being shown for requests to the backend.

    I noticed that Stefani posted about this method yesterday in the blog.
  6. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    08 Feb 2013 in reply to Nattawut
    Link to this post

    Thanks everyone for the input, this helped us as well.

     We added the ReturnUrl attribute which seems to work as expected. 

     

    void OnUnauthorizedAccess(IUnauthorizedPageAccessEvent unauthorizedEvent)
    {
        var url = unauthorizedEvent.Page.Url.TrimStart('~');
        HttpContext.Current.Response.Redirect("/login.aspx?ReturnUrl=" + Uri.EscapeDataString(url));
    }

    Regards,

    Jacques

6 posts, 0 answered