I have created 3 folders to manage users in ASP.NET and i also created 3 roles by the name of officer, user and admin.now based on the following code user can redirect to specific page, but now the problem is that i can't see the username after login which were added using loginName and LoginStatus automatically change from logout to login. it seems that user did not log in and asking to log in again. (funny problem.....)
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (Membership.ValidateUser(Login1.UserName, Login1.Password))
{
//Perform setting cookie information
e.Authenticated = true;
if (Roles.IsUserInRole(Login1.UserName, "r_admin"))
{
Response.Redirect("admin/default.aspx");
}
if (Roles.IsUserInRole(Login1.UserName, "r_officer"))
{
Response.Redirect("~/officer/default.aspx");
}
if (Roles.IsUserInRole(Login1.UserName, "r_user"))
{
Response.Redirect("~/user/default.aspx");
}
}
Try moving the Response.Redirect instructions to the LoggedIn event, instead of the Authenticate event.
on your login control add the Loggedin event like this:
and in the code behind:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.loggedin.aspx