protected void SignOutbtn_Click(object sender, EventArgs e) { //var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; //authenticationManager.SignOut(); //Response.Redirect("~/Login.aspx"); ASPNETIdentityCLP.Authorizer A = new ASPNETIdentityCLP.Authorizer(); A.SignOut(); Response.Redirect("~/Login.aspx"); }
protected void Loginbtn_Click(object sender, EventArgs e) { //var userStore = new UserStore<IdentityUser>(); //var userManager = new UserManager<IdentityUser>(userStore); //var user = userManager.Find(Uname.Text, Pwd.Text); //if (user != null) //{ // var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; // var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); // authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, userIdentity); // Response.Redirect("~/Login.aspx"); //} //else //{ // LoginStatus.Text = "Invalid username or password."; // LoginStatus.Visible = true; //} ASPNETIdentityCLP.Authorizer A = new ASPNETIdentityCLP.Authorizer(); string st = A.Login(Uname.Text, Pwd.Text); Response.Redirect("~/Login.aspx"); }
protected void Registerbtn_Click(object sender, EventArgs e) { ////// Default UserStore constructor uses the default connection string named: DefaultConnection ////var userStore = new UserStore<IdentityUser>(); ////var manager = new UserManager<IdentityUser>(userStore); ////var user = new IdentityUser() { UserName = UserName.Text }; ////IdentityResult result = manager.Create(user, Password.Text); ////if (result.Succeeded) ////{ //// StatusMessage.Text = string.Format("User {0} was created successfully!", user.UserName); ////} ////else ////{ //// StatusMessage.Text = result.Errors.FirstOrDefault(); ////} ASPNETIdentityCLP.Authorizer A = new ASPNETIdentityCLP.Authorizer(); string RS = A.Register(Uname.Text, Pwd.Text); Response.Redirect("~/Login.aspx"); //// Default UserStore constructor uses the default connection string named: DefaultConnection //var userStore = new UserStore<IdentityUser>(); //var manager = new UserManager<IdentityUser>(userStore); //var user = new IdentityUser() { UserName = Uname.Text }; //IdentityResult result = manager.Create(user, Pwd.Text); //if (result.Succeeded) //{ // ////======= Role management // var rolestore = new RoleStore<IdentityRole>(); // var rolemanager = new RoleManager<IdentityRole>(rolestore); // var role = new IdentityRole { Id = "Techs", Name = "Techs" }; // rolemanager.Create(role); // //var userRoles = await UserManager.GetRolesAsync(user.Id); // //selectedRole = selectedRole ?? new string[] { }; // //var result = await UserManager.AddToRolesAsync(user.Id, // // selectedRole.Except(userRoles).ToArray<string>()); // //manager.AddToRoles(user.Id, roles[]) // string[] SelectedRoles = { "BusOp","Tech"}; // manager.AddToRoles(user.Id, SelectedRoles); // //result = await UserManager.RemoveFromRolesAsync(user.Id, // // userRoles.Except(selectedRole).ToArray<string>()); // ////===== // var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;//Microsoft.Owin.Host.SystemWeb added manually by browsing in Nuget // var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); // authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent=false }, userIdentity); // Response.Redirect("~/Login.aspx"); // //=========== // //ApplicationSignInManager asi = new ApplicationSignInManager(); // //asi.PasswordSignInAsync(user.UserName, "", false, false); // //=========== //} //else //{ // RegisterStatus.Text = result.Errors.FirstOrDefault(); //} }