I've got a simple page View
in ASP.NET MVC with
@HttpContext.Current.Session["User"].ToString() @DateTime.Now
I simply want to programmatically set the user's identity so that when I re-navigate to this page or any other I can get the current user identity.
Also when navigate new User I need create a new User identity.
This is the controller
[HttpGet]
[OutputCache(NoStore = true, Duration = 60, VaryByParam = "*")]
public ActionResult Index()
{
var pModel = new PModel
{
Countries = PopulateDropDown(" SELECT ... ")
};
HttpContext.Session["User"] = HttpContext.User.Identity.Name.ToString();
HttpContext.Session.Timeout = 300;
return View(pModel);
}
This is the value printed on the page View
if I'm connected to app from desktop pc
myDomain\myUser 22/01/2021 19:53:15
Now I have tried connected to app from my mobile device with new user and the value printed on the page View
is
myDomain\myUser2 22/01/2021 20:04:37
But when refresh the browser on my desktop pc value printed on the page View
is changed to
myDomain\myUser2 22/01/2021 20:08:25
The user myUser2
replaced on the app the first connected user myUser
The same happens if I move in reverse, that is mobile device vs desktop pc...
Are there special considerations for this?
In the ASP.NET MVC project using without problem... for each user I have the corresponding Session without replace user...
I don't understand this problem in my ASP.NET MVC application... I'm sorry...
public static string tUser
{
get
{
if (HttpContext.Current.Session["tUser"] != null)
{
return HttpContext.Current.Session["tUser"].ToString();
}
return null;
}
set
{
HttpContext.Current.Session["tUser"] = value;
}
}
Update #1
Update #2
[HttpGet]
[OutputCache(NoStore = true, Duration = 60, VaryByParam = "*")]
public ActionResult Index()
{
System.Web.HttpContext.Current.Session["User"] = HttpContext.User.Identity.Name.ToString();
System.Web.HttpContext.Current.Session.Timeout = 300;
var pModel = new PModel
{
Countries = PopulateDropDown(" SELECT ... ")
};
return View(pModel);
}