How can one redirect after login?

Posted by Community Admin on 03-Aug-2018 19:40

How can one redirect after login?

All Replies

Posted by Community Admin on 09-Aug-2012 00:00

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

Posted by Community Admin on 14-Aug-2012 00:00

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

Posted by Community Admin on 14-Aug-2012 00:00

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.  


Posted by Community Admin on 15-Aug-2012 00:00

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?

Posted by Community Admin on 17-Aug-2012 00:00

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
[View:/cfs-file/__key/communityserver-discussions-components-files/295/fcd6184f_2D00_30b1_2D00_4a4c_2D00_813c_2D00_1dba03b1c009_5F00_LoginAndRedirect.rar:320:240]

Posted by Community Admin on 03-Sep-2012 00:00

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

Posted by Community Admin on 05-Sep-2012 00:00

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

This thread is closed