Change login page only for Front-end website

Posted by Community Admin on 03-Aug-2018 09:38

Change login page only for Front-end website

All Replies

Posted by Community Admin on 21-Jan-2013 00:00

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?

Posted by Community Admin on 21-Jan-2013 00:00

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

Posted by Community Admin on 29-Jan-2013 00:00

Hi Arno,

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

Nattawut

Posted by Community Admin on 02-Feb-2013 00:00

@Arno,
  If you type in /Sitefinity/Pages (for example, not logged in)...does this trigger for you?

Posted by Community Admin on 02-Feb-2013 00:00

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.

Posted by Community Admin on 08-Feb-2013 00:00

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

This thread is closed