[英]Different multiple logins in the same browser at same time not working in MVC
I'm using MVC 5 , when i Publish MVC Application on IIS then login with two different username like first is "A" and other is "B" .When I login Successful then login with B at same browser login successful 我正在使用MVC 5,当我在IIS上发布MVC应用程序时,然后使用两个不同的用户名登录,例如第一个是“ A” ,另一个是“ B” 。当我成功登录时,然后以相同的浏览器登录名成功登录
But the Problem is when i refresh A then username B has login so we can not login one browser with different name, i want to create different user can login at same browser and same PC How can i do this . 但是问题是当我刷新A时,用户名B已经登录,因此我们不能使用相同的名称登录一个浏览器,我想创建不同的用户,可以在同一浏览器和同一台PC上登录。
Controller
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(LeadUsers log, string returnUrl)
{
if (ModelState.IsValid)
{
System.Data.DataTable mDT_User = log.loginUser(log.Username, log.Password);
if (mDT_User.Rows.Count > 0)
{
FormsAuthentication.SetAuthCookie(log.Username, true);
Session["AgentID"] = int.Parse(mDT_User.Rows[0][0].ToString());
Session["AgentName"] = mDT_User.Rows[0][1].ToString().Trim();
Session["User_Type"] = mDT_User.Rows[0][2].ToString().Trim();
clsCommon._AgentID = int.Parse(mDT_User.Rows[0][0].ToString());
clsCommon._AgentName = mDT_User.Rows[0][1].ToString().Trim();
clsCommon._UserType = mDT_User.Rows[0][2].ToString().Trim();
clsCommon._GroupID = int.Parse(mDT_User.Rows[0][3].ToString());
// User Role
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("select A.Screen_Id, S.Screen_Name, Allow_Access, Access_Level from BriskSecurity.dbo.Module_Screens_Access A " +
"inner join BriskSecurity.dbo.Module_Screens S on S.Mod_id=A.Mod_Id and S.Screen_Id=A.Screen_Id " +
"where A.Mod_Id=14 and A.Group_Id=" + clsCommon._GroupID + "", con))
{
clsCommon._DT_Access = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(clsCommon._DT_Access);
}
}
return RedirectToAction("Index", "Dashboard"); // return index.chtml if user is valid.
}
else
{
TempData["Message"] = "Invalid Username OR Password"; // return the same view with message "Invalid username and password"
return RedirectToAction("Login");
}
}
else
{
return RedirectToAction("Login"); // return the same view with Validation Error.
}
}
Login Function 登录功能
public DataTable loginUser(string username, string password)
{
string constring = ConfigurationManager.ConnectionStrings["Real"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
password = Cryptographer.Encrypt(password);
con.Open();
using (SqlCommand cmd = new SqlCommand("select User_Id, User_Name,User_Type, Group_Id from BriskSecurity.dbo.Users where User_Login='" + username + "' and User_password='" + password + "' ", con))
{
DataTable mDT_User = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(mDT_User);
return mDT_User;
}
}
}
It is possible though to login with two different users. 但是可以用两个不同的用户登录。 The first one is a regular login session.
第一个是常规登录会话。 For the second user, open a Private Window (Firefox) or Incognito Window (Chrome) and login using the credentials of the second user, which operates in an isolated context.
对于第二个用户,请打开一个私有窗口(Firefox)或隐身窗口(Chrome),然后使用在一个独立的上下文中运行的第二个用户的凭据登录。 If you want more than two concurrent logins, you have to use a second browser.
如果要同时进行两次以上的登录,则必须使用第二个浏览器。 So for instance when using Chrome and Firefox you can have a total of four concurrent user sessions.
因此,例如,在使用Chrome和Firefox时,您总共可以有四个并发用户会话。
Change in the Web.Config file. 在Web.Config文件中更改。 In the forms authentication forms cookieless ="UseUri"
在表单身份验证表单中,无cookie =“ UseUri”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.