How to redirect a user to a particular URL in case the user has a specific role

   —   
This article describes how to redirect a user to a particular URL in case the user has a specific role, after user log in using a LogonForm web part.
At first please note, that you can set starting alias path for every user in Site Manager -> Administration -> Users -> edit -> General tab -> Starting alias path property.
If you do not want to set this property for every user, but rather for a whole role(s), you can modify <project folder>\CMSWebParts\Membership\LogonForm.ascx file and put following code into Login1_LoggedIn method:

string iName = this.Login1.UserName;
CMS.MembershipProvider.CMSMembershipProvider prov = new CMS.MembershipProvider.CMSMembershipProvider();
CMS.MembershipProvider.CMSMembershipUser custom = (CMS.MembershipProvider.CMSMembershipUser)prov.GetUser(iName, true);

if (custom.UserInfoMembership.IsInRole("Custom", "CorporateSiteASPX"))
{

Response.Redirect("http://www.google.com");

}

else {

//rest of default code

Custom” is the code-name of appropriate role, “CorporateSiteASPX” is the code-name of appropriate site.


See also:

Applies to: Kentico CMS 4.x
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.