- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我从 VS2013 中的 ASP.net 默认模板开始。我想获取当前用户对象。这应该可以在不直接访问数据库的情况下实现。
应该是这样
var currentUser = manager.FindById(User.Identity.GetUserId());
但是缺少 FindById!几个小时以来,我一直在尝试改用 FindByIdAsync。但我想我遇到了死锁。
public class UserManager : UserManager<IdentityUser>
{
public UserManager()
: base(new UserStore<IdentityUser>(new ApplicationDbContext()))
{
}
public async System.Threading.Tasks.Task<IdentityUser> GetCurrentUser()
{
var user = await FindByIdAsync(HttpContext.Current.User.Identity.Name);
return user;
}
}
调用属性:
private IdentityUser_CurrentUser;
protected IdentityUser CurrentUser
{
get
{
if (_CurrentUser == null)
{
var manager = new UserManager();
var result = manager.GetCurrentUser();
//-- STOPS HERE!!
_CurrentUser = result.Result;
}
return _CurrentUser;
}
}
任何帮助将不胜感激!向我展示 FindById 在哪里消失或如何使我的代码工作。或者还有另一种加载 IdentityUser 的方法吗?
已添加
在用户管理器中,没有找到FindById
,但是找到了this.FindById
。我将添加屏幕截图。这不是一个合适的解决方案,因为我不明白为什么会这样,或者有人可以解释这种行为吗?我附加了 2 个打开智能感知的屏幕。我还想提一下,这不是智能感知的问题 - 如果我不添加 this.
智能感知输入“Fi”:
.
智能感知输入“this.Fi”:
这样一来,至少我不再卡住了。
最佳答案
FindById
是来自 Microsoft.AspNet.Identity.UserManagerExtensions
类的扩展方法。它是 Microsoft.AspNet.Identity.Core
nuget 包的一部分。
你应该添加
using Microsoft.AspNet.Identity;
到您的代码以开始使用非异步方法。
关于c# - ASP.net identity : How to get current IdentityUser (ApplicationUser)? UserManager.FindById 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25483227/
我想从特定的本地对象中检索数据 var db=[ { "_id": "543adb9c7a0f149e3ac29438", "name": "user1", "email":
即使数据库中存在 id,以下 findById() 也会返回 null: router.get('/product/:id', function (req, res) { console.log("p
我有以下 dart 类,它加载一个对象和一个图像。当我执行热重载时,函数 findById 返回错误消息 Bad State: No element .在调试时,我看到我正在查询的列表是空的,一旦我进
我有运行 Mongoose 并成功返回以下结果的代码。 为什么我不能执行以下操作并从我的对象中获取值? Object.keys(result).forEach(function(record){
尝试使用 Axios.get 方法获取 ':id'S̶e̶r̶v̶e̶r̶̶i̶s̶̶r̶e̶s̶p̶o̶n̶d̶i̶n̶g̶̶w̶i̶t̶h̶̶a̶̶4̶0̶4̶ 目前我无法设置组件的状态。我得到一
hibernate 有一个特殊的问题。我有一个像这样的 hibernate 功能。 @SuppressWarnings("unchecked") public List findByResponseI
我在网上找到了以下代码,用于从数据库中获取对象。现在lock表示什么?什么时候锁? public T findById(ID id, boolean lock) { T entity;
我在使用 spring 3 和 hibernate-core 3.5.1-Final 的网络应用程序中遇到了一个非常奇怪的行为。 为了简单起见,我提供了我的代码.. if(ripid!=null){
我创建了 2 个表,名为:groupusermaps 和 groups。从 groupusermaps 中,我获取所有 groupId,并且这些 groupId 传入 findById() 方法,以获
我有三个实体。(我使用 xxx 作为这个例子的占位符) 我已经设置了他们所有的 @Entities与 @Entity @Table(name = "xxx") public class xxx { @
PHP 版本:5.2.17 CakePHP 版本:1.3.11 MySQL版本:5.5.9 我正在为客户开发一个非常简单的内部留言板网站。由于它仅供内部使用,因此客户要求没有用户名和密码,只有密码。没
我们有一个使用“findById”的非常简单的方法。 public Cart getCart(long cartId) { Cart cart = null; try {
我正在运行 Mongoose,我有一个工作连接,并且 findById()有时会返回结果: 情况1:无意义查询 models.Repo.findById("somefakeid", function(
列表项 var express = require("express"); var app = express(); var Mongoose = require("Mongoose"); Mongo
我正在尝试通过 mongodb 的对象 ID 获取项目对象,但是当我尝试在 postman 中调用该路由时,它会为我提供数据库中每个对象的列表(总共 4 个对象),而不是预期一个对象。 这是我为从数据
我有一个 Mongoose 模型,例如; var Schema = new Schema({ title: { type: String, required: true }, subtitle
我正在使用 mongoose 调用 findById,它没有返回所有字段,或者至少没有正确映射到字段。但如果我使用聚合,它会返回该字段 我有以下架构 const ratingSchema = new
我在使用 ButterKnife 时遇到此错误: error: cannot find symbol method findById(View,int) TextView tvHeaderTextOn
使用 Hibernate 获取的实体的所有字段都设置为 NULL。我怎样才能避免这种情况?这是我的 Jpa 存储库。 @Repository public interface PolicyReposi
我正在使用 Spring 和 JPA(带有 MySQL 的 Hibernate)以及 Lombok。 您好,我的实体的这一部分: @Data @AllArgsConstructor @NoArgsCo
我是一名优秀的程序员,十分优秀!