Am using forms authentication along with the asp.net login controls in my website. Based on the roles i have to redirect my users to two different pages.
The code works but occasionally it takes me to either default.aspx which is not present and sometimes it simple refreshes my current login page. Any help is appreciated.
Here is my code behind
protected void Login1_LoggedIn(object sender, EventArgs e)
{
string[] rolenames = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name);
if (rolenames.Length > 0)
{
if (rolenames[0] == "Administrators")
Response.Redirect("~/Administrators/Home.aspx");
else if (rolenames[0] == "Employees")
Response.Redirect("~/Employees/Home.aspx");
}
}
and following markup from web.config
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx"
slidingExpiration="true"
cookieless="AutoDetect"
></forms>
</authentication>