简体   繁体   English

同一浏览器中的不同多次登录无法同时在MVC中使用

[英]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.

相关问题 在ASP网站中不允许同时多次登录 - Not allowing multiple logins at the same time in asp website 使用不同的变量同时运行多个相同的线程 - Running multiple of same thread at same time with different variables 同步多个流程以同时开始工作? - Synchronize multiple processes to begin working at the same time? 在不同的登录名下在同一台机器上安装clickonce应用程序 - install clickonce application on the same machine, under different logins 同时使用多个实例化的设计解决方案 - Design solution for working with multiple instantiations at the same time C#MVC3 Web应用程序中同时存在不同的线程 - Different Thread at same time in C# MVC3 Web Application MVC model 使用存储过程同时更新和创建(多个) - MVC model update and create (multiple) at the same time using stored procedure MVC - 有一种方法可以在具有相同属性,不同名称的模型中声明多个属性 - MVC - is there a way to declare multiple properties in a model with the same attributes, different names 不同MVC区域中的多个API控制器共享同一名称空间 - Multiple API controllers in different MVC Areas share the same namespace 为同时使用不同浏览器的不同用户锁定方法/代码以使用此方法 - Lock the method/code for different different user which is using different browser at same time to acces this method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM