Change login page only for Front-end website
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?
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
Hi Arno,
Thank you very much. It works as expected. ;)
Nattawut
@Arno,
If you type in /Sitefinity/Pages (for example, not logged in)...does this trigger for you?
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.
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