Asp.Net表单身份验证:会话自动更改为其他最近登录的用户会话

问题描述 投票:1回答:1

我的asp.net Web窗体应用程序,通过表单身份验证托管在Intranet中的IIS8上。对于一次单个用户而言,此应用程序可以正常运行。但是问题出在多个用户身上。以两个用户为例来说明问题。

问题是当UserA登录到应用程序并执行任何导航时。同时,其他UserB登录到该应用程序并执行任何导航。现在同时,如果userA刷新浏览器,则UserA会意识到他的会话转换为UserB会话(最近登录),这也很奇怪。两个用户都在不同的机器/系统和位置上。我不知道该怎么称呼这个问题。

我认为我的配置/代码中缺少某些地方。我的代码和配置在下面给出。

在C#中,验证用户凭据后,我正在使用以下代码FormsAuthentication.RedirectFromLoginPage(UserId, false);

在Web.config中

<sessionState mode="InProc" timeout="20"></sessionState>    
<authentication mode="Forms">
  <forms name=".ASPXFORMSAUTH" loginUrl="LogIn.aspx" cookieless="UseCookies" requireSSL="false" path="/" timeout="30" defaultUrl="Welcome.aspx" protection="All"/>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>

我正在使用以下URL访问托管的应用程序:

http://SERVER_NAME:8020/LogIn.aspx

请提出建议,我做错了什么或缺少任何重要步骤。

c# asp.net forms-authentication iis-8 asp.net-session
1个回答
0
投票

成功登录后尝试登录SessionID,以确保这些会话相同。此外,在重定向逻辑期间可能会生成相同的身份验证票证。这取决于我们如何控制Cookie的生成。

  private void cmdLogin_ServerClick(object sender, System.EventArgs e)
{
   if (ValidateUser(txtUserName.Value,txtUserPass.Value) )
   {
      FormsAuthenticationTicket tkt;
      string cookiestr;
      HttpCookie ck;
      tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now, 
DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
      cookiestr = FormsAuthentication.Encrypt(tkt);
      ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
      if (chkPersistCookie.Checked)
      ck.Expires=tkt.Expiration;
    ck.Path = FormsAuthentication.FormsCookiePath; 
      Response.Cookies.Add(ck);

      string strRedirect;
      strRedirect = Request["ReturnUrl"];
      if (strRedirect==null)
            strRedirect = "default.aspx";
         Response.Redirect(strRedirect, true);
   }
   else
      Response.Redirect("logon.aspx", true);
}

请检查以获取更多详细信息。https://support.microsoft.com/en-us/help/301240/how-to-implement-forms-based-authentication-in-your-asp-net-applicatio随时让我知道问题是否仍然存在。

© www.soinside.com 2019 - 2024. All rights reserved.