1

我的 asp.net webform 应用程序托管在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

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

4

1 回答 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-applicio
如果问题仍然存在,请随时告诉我.

于 2020-06-10T10:08:46.153 回答