asp.net - 登录过程中 User.Identity.GetUserId() 的 ASP.NET MVC5 身份问题
问题描述
我在我的应用程序中使用 Asp.net Identity 2。我得到这样的当前用户ID:
User.Identity.GetUserId()
它工作正常,但是当我登录到我的仪表板,然后像这样从仪表板创建用户时:
User.Identity.GetUserId()
id 替换为插入的用户。
我该如何解决这个问题?
解决方案
如果您使用的是 default 之类的实现AccountController::Register
,请注意此操作会在注册后登录新用户,即:
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
在您的实现中删除该行应该没问题。
推荐阅读
- android - 在 Android Studio 中生成签名的 apk 时发生错误
- java - 从配置中动态读取@JsonProperty
- sql-server - SQL Server全文搜索:词的解析形式不同的结果
- c# - Enterprise Architect的元素注释中未显示新行
- react-native - React Native:无法使用地理定位 API 访问位置
- python - Pandas:如何按索引值添加行值
- php - Doctrine ORM:按 2 个类别过滤文章
- angular - angular 2+中的通用组件+通用服务
- xml - 如何验证嵌套元素中的唯一属性?
- java - Tomcat 9 在 Ubuntu 上无法与 Java 10 一起使用