C# asp.net web窗体应用程序不允许多用户会话

C# asp.net web窗体应用程序不允许多用户会话,c#,asp.net,session,webforms,C#,Asp.net,Session,Webforms,我的asp.net 4.5 web窗体应用程序不允许多个会话或会话超时等。第一个或两个人成功登录并使用系统,直到第三个或更多人尝试登录并将其重定向到登录页面。点击F12,我得到以下信息 密码字段存在于具有不安全(http://)表单的表单中 行动。这是一种安全风险,允许用户登录凭据 被偷 这是我的登录按钮代码: protected void btnLogin_Click(object sender, EventArgs e) { ApplicationDbCont

我的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.");
        }
    }
protectedvoidbtnlogin\u单击(对象发送方,事件参数e)
{
ApplicationDbContext_db=新的ApplicationDbContext();
var userStore=新的userStore(_db);
var userManager=newusermanager(userStore);
ApplicationUser user=userManager.Find(txtserName.Text,txtPassword.Text);
如果(用户!=null)
{
if(user.IsDeleted&&user.UserName.ToLower()!=ApplicationBinInitializer.UserName.ToLower())
{
AddModelError(“错误”,“您的帐户已被删除。”);
}
如果(!user.IsActive&&user.UserName.ToLower()!=ApplicationBinInitializer.UserName.ToLower()),则为else
{
AddModelError(“错误”,“您的帐户已被禁用。”);
}
其他的
{
IAAuthenticationManager authenticationManager=HttpContext.Current.GetOwinContext().Authentication;
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
ClaimsIdentity identity=userManager.CreateIdentity(user,DefaultAuthenticationTypes.applicationcokie);
AuthenticationProperties props=新的AuthenticationProperties();
props.ispersist=chkremberme.Checked;
authenticationManager.SignIn(道具、身份);
如果(!string.IsNullOrEmpty(Request.QueryString[“ReturnUrl”]))
{
Response.Redirect(Request.QueryString[“ReturnUrl”]);
}
else if(userManager.IsInRole(user.Id,“Admin”))
{
重定向(“~/admin/index”);
}
其他的
{
重定向(“~/user/index”);
}
}
}
其他的
{
AddModelError(“错误”,“无效的用户名或密码”);
}
}



好的。试试这个。希望它能起作用

    <system.web>
    <sessionState cookieless="true" regenerateExpiredSessionId="true" timeout="2880" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>

好的。试试这个。希望它能起作用

    <system.web>
    <sessionState cookieless="true" regenerateExpiredSessionId="true" timeout="2880" />
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>
<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>


您是否通过HTTPS部署站点?如果是这样,我认为您的登录
标记中有一个硬编码的Yeo,它指向一个不安全的HTTP url。更新标记以包含相对路径,并且不要在HTML中对协议进行编码

您是否通过HTTPS部署站点?如果是这样,我认为您的登录
标记中有一个硬编码的Yeo,它指向一个不安全的HTTP url。更新标记以包含相对路径,并且不要在HTML中对协议进行编码

嗨,我也包括:我只包括在我的web.config文件中是的。甚至包括
httpModules
。正如您所说,该应用程序允许2个用户登录。但是如果有两个以上的用户登录,那么所有用户的会话都会结束吗?或者会话是否仅针对前两个用户之外的额外用户结束?嗨,我也包括:am仅包括在我的web.config文件中是的。甚至包括
httpModules
。正如您所说,该应用程序允许2个用户登录。但是如果有两个以上的用户登录,那么所有用户的会话都会结束吗?或者会话是否仅针对前两个用户之外的额外用户结束?我没有通过https进行部署。您提到的标签硬编码Yeo在代码中的什么位置?您能提供更多信息吗???在aspx页面中,我想您正在寻找类似
的标签。通常在母版页上。虽然已经很长时间了,所以我可能记错了。我不是通过https部署的。您提到的标签硬编码Yeo在代码中的什么位置?您能提供更多信息吗???在aspx页面中,我想您正在寻找类似
的标签。通常在母版页上。但这已经是很长时间了,所以我可能记错了。