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
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 .
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;
}
}
}