【发布时间】:2016-05-16 02:39:05
【问题描述】:
我的 asp.net 4.5 Web 表单应用程序不允许多个会话或会话超时等。第一个或两个人成功登录并使用系统,直到第三个或更多人尝试登录并将他们重定向到登录页面。按 F12 我收到以下消息
密码字段出现在带有不安全 (http://) 表单的表单中 行动。这是一个安全风险,允许用户登录凭据 被盗
这是我的登录按钮代码:
protected void btnLogin_Click(object sender, EventArgs e)
{
ApplicationDbContext _db = new ApplicationDbContext();
var userStore = new UserStore<ApplicationUser>(_db);
var userManager = new UserManager<ApplicationUser>(userStore);
ApplicationUser user = userManager.Find(txtUserName.Text, txtPassword.Text);
if (user != null)
{
if (user.IsDeleted && user.UserName.ToLower() != ApplicationDbInitializer.userName.ToLower())
{
ModelState.AddModelError("Error", "Your account has been deleted.");
}
else if (!user.IsActive && user.UserName.ToLower() != ApplicationDbInitializer.userName.ToLower())
{
ModelState.AddModelError("Error", "Your account has been disabled.");
}
else
{
IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
ClaimsIdentity identity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationProperties props = new AuthenticationProperties();
props.IsPersistent = chkRememberMe.Checked;
authenticationManager.SignIn(props, identity);
if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
{
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
else if (userManager.IsInRole(user.Id, "Admin"))
{
Response.Redirect("~/admin/index");
}
else
{
Response.Redirect("~/user/index");
}
}
}
else
{
ModelState.AddModelError("Error", "Invalid username or password.");
}
}
【问题讨论】:
标签: c# asp.net session webforms