是否可以为 ServiceStack 的身份验证功能指定架构?
Is it possible to specify the schema for ServiceStack's Auth Feature?
ServiceStack.Ormlite 允许我们使用 Schema 属性来装饰数据库 table 类 来表示它们在数据库中属于哪个模式。
这对所有 table 都非常有用,但似乎是由 Auth Feature 创建的那些除外。是否可以指定 Auth tables 应该属于哪个模式?我宁愿不使用自定义 类 纯粹用 Schema 属性进行装饰。
如果没有,我想我应该在某处请求更改?
编辑 1 - 按照 mythz 的建议
我已经在初始化构造函数中添加了属性..
public class AuthenticationInitialisation : AppInitialisation
{
private readonly IAppSettings _appSettings;
public AuthenticationInitialisation(IAppSettings appSettings)
{
_appSettings = appSettings;
typeof(UserAuth).AddAttributes(new SchemaAttribute("Admin"));
typeof(UserAuthDetails).AddAttributes(new SchemaAttribute("Admin"));
typeof(UserAuthRole).AddAttributes(new SchemaAttribute("Admin"));
}...
我已经从我的 SQL 用户中删除了默认架构,并且在 DropAndRecreateTables() 上遇到异常...
var authRepo = (OrmLiteAuthRepository)appHost.TryResolve<IUserAuthRepository>();
if (_appSettings.Get("RecreateAuthTables", false))
authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else...
异常显示为
Cannot drop the table 'UserAuth', because it does not exist or you do not have permission.
由 SQL 分析器验证显示以下内容已传递到 SQL 服务器
DROP TABLE "UserAuth"
编辑 2 - 更改为 MyGet 预发布 ServiceStack 版本
我现在收到以下错误..
An exception of type 'System.MissingMethodException' occurred in ServiceStack.dll but was not handled in user code
Additional information: Method not found: 'Void ServiceStack.MetadataTypesConfig..ctor(System.String, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, System.String, Boolean, Boolean, Boolean, Boolean, Boolean, System.Nullable`1)'.
堆栈跟踪..
at ServiceStack.NativeTypesFeature..ctor()
at ServiceStack.ServiceStackHost..ctor(String serviceName, Assembly[] assembliesWithServices)
at ServiceStack.Host.HttpListener.HttpListenerBase..ctor(String serviceName, Assembly[] assembliesWithServices)
at ServiceStack.AppHostHttpListenerBase..ctor(String serviceName, Assembly[] assembliesWithServices)
at MyProduct.AppHost..ctor(IEnumerable`1 initialisations) in d:\dev\App_Code\AppHost.cs:line 14
at MyProduct.Global.Application_Start(Object sender, EventArgs e) in d:\dev\Global.asax.cs:line 29
在我的 AppHost 构造函数上..
public AppHost(IEnumerable<IAppInitialisation> initialisations) : base("RESTful Web API", typeof(SystemsService).Assembly)
{
if (initialisations == null)
{
_initialisations = new IAppInitialisation[0];
}
else
{
_initialisations = initialisations.ToArray();
}
}
如果模式的使用将进入下一个 ServiceStack 版本,那么我将等待并暂时设置 SQL 用户的默认模式..
尝试将架构属性动态添加到 UserAuth 表,即:
typeof(UserAuth)
.AddAttributes(new SchemaAttribute("MySchema"));
typeof(UserAuthDetails)
.AddAttributes(new SchemaAttribute("MySchema"));
ServiceStack.Ormlite 允许我们使用 Schema 属性来装饰数据库 table 类 来表示它们在数据库中属于哪个模式。
这对所有 table 都非常有用,但似乎是由 Auth Feature 创建的那些除外。是否可以指定 Auth tables 应该属于哪个模式?我宁愿不使用自定义 类 纯粹用 Schema 属性进行装饰。
如果没有,我想我应该在某处请求更改?
编辑 1 - 按照 mythz 的建议
我已经在初始化构造函数中添加了属性..
public class AuthenticationInitialisation : AppInitialisation
{
private readonly IAppSettings _appSettings;
public AuthenticationInitialisation(IAppSettings appSettings)
{
_appSettings = appSettings;
typeof(UserAuth).AddAttributes(new SchemaAttribute("Admin"));
typeof(UserAuthDetails).AddAttributes(new SchemaAttribute("Admin"));
typeof(UserAuthRole).AddAttributes(new SchemaAttribute("Admin"));
}...
我已经从我的 SQL 用户中删除了默认架构,并且在 DropAndRecreateTables() 上遇到异常...
var authRepo = (OrmLiteAuthRepository)appHost.TryResolve<IUserAuthRepository>();
if (_appSettings.Get("RecreateAuthTables", false))
authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
else...
异常显示为
Cannot drop the table 'UserAuth', because it does not exist or you do not have permission.
由 SQL 分析器验证显示以下内容已传递到 SQL 服务器
DROP TABLE "UserAuth"
编辑 2 - 更改为 MyGet 预发布 ServiceStack 版本
我现在收到以下错误..
An exception of type 'System.MissingMethodException' occurred in ServiceStack.dll but was not handled in user code
Additional information: Method not found: 'Void ServiceStack.MetadataTypesConfig..ctor(System.String, Boolean, Boolean, Boolean, Boolean, Boolean, Boolean, System.String, Boolean, Boolean, Boolean, Boolean, Boolean, System.Nullable`1)'.
堆栈跟踪..
at ServiceStack.NativeTypesFeature..ctor() at ServiceStack.ServiceStackHost..ctor(String serviceName, Assembly[] assembliesWithServices) at ServiceStack.Host.HttpListener.HttpListenerBase..ctor(String serviceName, Assembly[] assembliesWithServices) at ServiceStack.AppHostHttpListenerBase..ctor(String serviceName, Assembly[] assembliesWithServices) at MyProduct.AppHost..ctor(IEnumerable`1 initialisations) in d:\dev\App_Code\AppHost.cs:line 14 at MyProduct.Global.Application_Start(Object sender, EventArgs e) in d:\dev\Global.asax.cs:line 29
在我的 AppHost 构造函数上..
public AppHost(IEnumerable<IAppInitialisation> initialisations) : base("RESTful Web API", typeof(SystemsService).Assembly)
{
if (initialisations == null)
{
_initialisations = new IAppInitialisation[0];
}
else
{
_initialisations = initialisations.ToArray();
}
}
如果模式的使用将进入下一个 ServiceStack 版本,那么我将等待并暂时设置 SQL 用户的默认模式..
尝试将架构属性动态添加到 UserAuth 表,即:
typeof(UserAuth)
.AddAttributes(new SchemaAttribute("MySchema"));
typeof(UserAuthDetails)
.AddAttributes(new SchemaAttribute("MySchema"));