質問

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

役に立ちましたか?

解決

The auth cookie is stored by the browser, for the browser. You'll have to perform the login with each of your browsers that you want to use.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top