c# - 为什么检查角色需要跨分区查询?
问题描述
在 azure 门户上,我创建了 Cosmos DB(核心 (SQL) API),并在其中添加了一个users
容器(分区键id
)和roles
(分区键name
)。安装CodeKoenig.AspNetCore.Identity.DocumentDb
包。然后,当我尝试通过角色管理器确定数据库中是否存在角色时,我得到一个DocumentClientException: Cross partition query is required but disabled. Please set x-ms-documentdb-query-enablecrosspartition to true, specify x-ms-documentdb-partitionkey, or revise your query to avoid this exception
. 这就是我配置身份服务的方式:
services.AddIdentity<Models.Entities.User, DocumentDbIdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
.AddDocumentDbStores(options =>
{
options.Database = "forumdb";
options.UserStoreDocumentCollection = "users";
options.RoleStoreDocumentCollection = "roles";
})
.AddDefaultTokenProviders();
引发异常的代码:
var roleManager = serviceProvider.GetRequiredService<RoleManager<DocumentDbIdentityRole>>();
roleManager.RoleExistsAsync(roleName).Result;
Models.Entities.User
继承自AspNetCore.Identity.DocumentDb.DocumentDbIdentityUser
。我怀疑应该有一个跨分区请求来检查角色是否存在。我做错了什么或如何x-ms-documentdb-query-enablecrosspartition
设置true
请求RoleManager
?
解决方案
推荐阅读
- flutter - Flutter orderby json数据
- java - 反应式 - 改进 Mono 语法
- css - CSS制作表格有可移动的列
- r - 将环境中的 data.frame 对象附加到 R 中 GlobalEnv(或另一个环境)中的相应 data.frame 对象
- javascript - 在 preventDefault 不做默认值之后点击
- node.js - 创建模型后是否可以创建一个新的钩子?
- sqlite - 创建不允许不在另一列中的值的触发器
- r - R plm vs fixst 包 - 不同的结果?
- c# - 用 C# 编写的 ASP.NET MVC 5 Web 应用程序中的视频通话开发
- docker - 如何使用 Dockerfile 在一层中复制或添加多个文件和目录