0

On my MVC 4 application I have a log in page which saves a user Id and transfers user to a Dashboard page in this way:

 var user = _userService.GetUserByCredentials(accountCredentials.Username.Trim(), accountCredentials.Password);

if (user != null)
{
    FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);
    return RedirectToAction("Index", "Dashboard");
}

If I log in with, for ex. Chrome I get transfered nicely to http://localhost:63377/Dashboard on which I use User.GetUserId()(on Dashboard controller):

_user = _userService.GetUserById(User.GetUserId());
Session["NimbleUser"] = _user.Firstname + " " + _user.Lastname;

An error is thrown if I copy the url(http://localhost:63377/Dashboard) to a Firefox, IE,... my _user on Dashboard controller is then null, probably because User.GetUserId() is null. How do I repair this so I can copy url to other browsers and that my application still works?

Thanks in advance

4

1 回答 1

0

auth cookie 由浏览器存储,供浏览器使用。您必须使用要使用的每个浏览器执行登录。

于 2014-05-07T11:24:16.123 回答