我正在尝试为 RavenDb 实现 ServiceStack 身份验证和授权。 ServiceStack UserAuth 模型的属性“Id”为 Int,而 RavenDb 除外“Id”为 String。
当我尝试创建新用户时,出现以下异常:
Message=Cannot set identity value 'UserAuths/1-A' on property 'Id' for type 'ServiceStack.Auth.UserAuth' because property type is not a string. Source=Raven.Client
我可以实现一个忽略 ServiceStack UserAuth 表的 custom_UserAuth 表吗?这是唯一的方法吗?
最佳答案
身份验证存储库必须至少实现 IUserAuth但您可以使用自己的具体 UserAuth 表,这就是 RavenDbUserAuthRepository允许使用通用 RavenDbUserAuthRepository<TUserAuth, TUserAuthDetails>
。
例如:您可以创建自定义 MyRavenDbUserAuthRepository
使用您自己的MyUserAuth
或MyUserAuthDetails
类(class):
public class MyRavenDbUserAuthRepository
: RavenDbUserAuthRepository<MyUserAuth, MyUserAuthDetails>, IUserAuthRepository
{
public RavenDbUserAuthRepository(IDocumentStore docStore) : base(docStore) { }
}
否则看起来 RavenDB 可以让你 customize which property to use as its Identity .
关于authentication - ServiceStack - UserAuth "Id"是 INT,而 RavenDb 预计 "Id"是 STRING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51880011/