protected void btLogin_Click(object sender, System.EventArgs e) { int orgId; string firstName; int userId; BWA.WebModules.ICredentialStore credentialstore = new BWA.WebModules.DBAuthentication(); if (credentialstore.Authenticate(tbLoginEmail.Text, tbPassword.Text, out orgId, out firstName, out userId)) { //Get users roles string[] roles = credentialstore.GetRoles(userId); StringBuilder rolesString = new StringBuilder(); foreach (string role in roles) { rolesString.Append(role); rolesString.Append(@";"); } //Build UserData String. Seperators "roles~15~OrgId~16~" string userData = ""; userData = rolesString.ToString() + "~15~" + orgId + "~16~"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, userId.ToString(), DateTime.Now, DateTime.Now.AddHours(3), false, userData ); //Encrypt the ticket string encryptedTicket = FormsAuthentication.Encrypt(ticket); //Create a cookie HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //write the cookie to the response Response.Cookies.Add(authenticationCookie); //redirect the user back to their original URL //Response.Redirect(FormsAuthentication.GetRedirectUrl(tbLoginEmail.Text,false)); //FormsAuthentication.GetRedirectUrl(tbLoginEmail.Text,false); //FormsAuthentication.SetAuthCookie(tbLoginEmail.Text,false); Response.Redirect("home/default.aspx"); } else { lbErr.Visible = true; } }
protected void btLogin_Click(object sender, System.EventArgs e) { int orgId; string firstName; int userId; BWA.WebModules.ICredentialStore credentialstore = new BWA.WebModules.DBAuthentication(); if (credentialstore.Authenticate(tbLoginEmail.Text,tbPassword.Text,out orgId, out firstName, out userId)){ //Get users roles string[] roles = credentialstore.GetRoles(userId); StringBuilder rolesString = new StringBuilder(); foreach(string role in roles){ rolesString.Append(role); rolesString.Append(@";"); } //Build UserData String. Seperators "roles~15~OrgId~16~" string userData=""; userData=rolesString.ToString()+"~15~"+orgId+"~16~"; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, userId.ToString(), DateTime.Now, DateTime.Now.AddHours(3), false, userData ); //Encrypt the ticket string encryptedTicket = FormsAuthentication.Encrypt(ticket); //Create a cookie HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket); //write the cookie to the response Response.Cookies.Add(authenticationCookie); //redirect the user back to their original URL //Response.Redirect(FormsAuthentication.GetRedirectUrl(tbLoginEmail.Text,false)); //FormsAuthentication.GetRedirectUrl(tbLoginEmail.Text,false); //FormsAuthentication.SetAuthCookie(tbLoginEmail.Text,false); Response.Redirect("home/default.aspx"); } else{ lbErr.Visible=true; } }