首页 > 解决方案 > 登录过程中 User.Identity.GetUserId() 的 ASP.NET MVC5 身份问题

问题描述

我在我的应用程序中使用 Asp.net Identity 2。我得到这样的当前用户ID:

User.Identity.GetUserId()

它工作正常,但是当我登录到我的仪表板,然后像这样从仪表板创建用户时:

User.Identity.GetUserId() 

id 替换为插入的用户。

我该如何解决这个问题?

标签: asp.netauthenticationasp.net-identity

解决方案


如果您使用的是 default 之类的实现AccountController::Register,请注意此操作会在注册后登录新用户,即:

await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

在您的实现中删除该行应该没问题。


推荐阅读