How can one redirect after login?
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
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.
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.
Just a quick update:
<
customErrors
mode
=
"RemoteOnly"
>
<
error
statusCode
=
"403"
redirect
=
"~/login"
/>
</
customErrors
>
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
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
>
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.