Mono 3.4.1 中的 UserCookieAuthentication [英] UserCookieAuthentication in Mono 3.4.1

查看:32
本文介绍了Mono 3.4.1 中的 UserCookieAuthentication的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将下面的行添加到我的 Startup 类时,我得到下面的异常.这是一个从单声道(Ubuntu)运行的自托管 exe.它在 Windows 中运行良好.我已经缩小了 UseCookieAuthentication 调用的范围.我可以毫无问题地实例化选项.知道这里发生了什么吗?我有 aspnet Identity 和 EF6/MySql.

When ever I add the line below to my Startup class I get the exception below. This is a self hosted exe running from mono (Ubuntu). It works fine in windows. I've narrowed it down the UseCookieAuthentication call. I can instantiate the options without any issue. Any idea what is going on here? I have aspnet Identity working and EF6/MySql.

app.UseCookieAuthentication(new CookieAuthenticationOptions());

未处理的异常:System.Reflection.TargetInvocationException:调用的目标已引发异常.---> System.TypeLoadException:无法从程序集Microsoft.Owin.Security,Version=2.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"加载类型Microsoft.Owin.Security.DataProtection.DpapiDataProtector".在 Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder,string[]) <0x00052>在 Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223>在(包装器动态方法)object.lambda_method(System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions)<0x00048>在(包装器托管到本机)System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)<0x00067>在 System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not load type 'Microsoft.Owin.Security.DataProtection.DpapiDataProtector' from assembly 'Microsoft.Owin.Security, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder,string[]) <0x00052> at Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223> at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00048> at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0x00067> at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>

--- 内部异常堆栈跟踪结束 ---在 System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object[] 参数,System.Globalization.CultureInfo 文化)[0x00000] 中:0在 System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] 参数) [0x00000] in :0在 System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0在 System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0在 System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0在 Microsoft.Owin.Builder.AppBuilder.BuildInternal(System.Type 签名)[0x00000] 中:0在 Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] in :0在 Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder 生成器)[0x00000] 中:0在 Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(Microsoft.Owin.Hosting.Engine.StartContext 上下文)[0x00000] 中:0在 Microsoft.Owin.Hosting.Engine.HostingEngine.Start(Microsoft.Owin.Hosting.Engine.StartContext 上下文)[0x00000] 中:0在 Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.Starter.HostingStarter.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider 服务,Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start[Startup](Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start[Startup] (System.String url) [0x00000] in :0在 HelloWorldNancy.Program.Main (System.String[] args) [0x00000] in :0[错误] 致命的未处理异常:System.Reflection.TargetInvocationException:调用目标已引发异常.---> System.TypeLoadException:无法从程序集Microsoft.Owin.Security,Version=2.1.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"加载类型Microsoft.Owin.Security.DataProtection.DpapiDataProtector".在 Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder,string[]) <0x00052>在 Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223>在(包装器动态方法)object.lambda_method(System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions)<0x00048>在(包装器托管到本机)System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)<0x00067>在 System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>

--- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0 at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0 at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0 at Microsoft.Owin.Builder.AppBuilder.BuildInternal (System.Type signature) [0x00000] in :0 at Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] in :0 at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create (IAppBuilder builder) [0x00000] in :0 at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in :0 at Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in :0 at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start[Startup] (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start[Startup] (System.String url) [0x00000] in :0 at HelloWorldNancy.Program.Main (System.String[] args) [0x00000] in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Could not load type 'Microsoft.Owin.Security.DataProtection.DpapiDataProtector' from assembly 'Microsoft.Owin.Security, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. at Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector (Owin.IAppBuilder,string[]) <0x00052> at Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor (Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00223> at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions) <0x00048> at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) <0x00067> at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x000d7>

--- 内部异常堆栈跟踪结束 ---在 System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object[] 参数,System.Globalization.CultureInfo 文化)[0x00000] 中:0在 System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] 参数) [0x00000] in :0在 System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0在 System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0在 System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0在 Microsoft.Owin.Builder.AppBuilder.BuildInternal(System.Type 签名)[0x00000] 中:0在 Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] in :0在 Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder 生成器)[0x00000] 中:0在 Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(Microsoft.Owin.Hosting.Engine.StartContext 上下文)[0x00000] 中:0在 Microsoft.Owin.Hosting.Engine.HostingEngine.Start(Microsoft.Owin.Hosting.Engine.StartContext 上下文)[0x00000] 中:0在 Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.Starter.HostingStarter.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider 服务,Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start[Startup](Microsoft.Owin.Hosting.StartOptions 选项)[0x00000] 中:0在 Microsoft.Owin.Hosting.WebApp.Start[Startup] (System.String url) [0x00000] in :0在 HelloWorldNancy.Program.Main (System.String[] args) [0x00000] in :0

--- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in :0 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0 at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in :0 at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in :0 at Microsoft.Owin.Builder.AppBuilder.BuildInternal (System.Type signature) [0x00000] in :0 at Microsoft.Owin.Builder.AppBuilder.Build (System.Type returnType) [0x00000] in :0 at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create (IAppBuilder builder) [0x00000] in :0 at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in :0 at Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in :0 at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start[Startup] (Microsoft.Owin.Hosting.StartOptions options) [0x00000] in :0 at Microsoft.Owin.Hosting.WebApp.Start[Startup] (System.String url) [0x00000] in :0 at HelloWorldNancy.Program.Main (System.String[] args) [0x00000] in :0

推荐答案

好的,这是因为 OWIN 默认使用 DpapiDataProtector,而 DPAPI 是 Windows API(数据保护 API),不能在单声道中工作.幸运的是,您可以覆盖 cookie 选项中的默认设置.下面是一个示例,其中 AesDataProtectorProvider 是我在此处找到的自定义 IDataProtector:跨多个使用 Oauth 票证服务?

Okay this is happening because OWIN uses DpapiDataProtector by default and DPAPI is a windows API (Data Protection API) and does not work in mono. Luckily you can override the default in your cookie options. Below is an example where AesDataProtectorProvider is a custom IDataProtector that I found here: Using Oauth tickets across several services?

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            TicketDataFormat =
                new SecureDataFormat<AuthenticationTicket>(DataSerializers.Ticket,
                    new AesDataProtectorProvider("testing"), TextEncodings.Base64)
        });

使用此代码,我的项目再次在 Mono 中启动.

With this code my project starts in Mono again.

更新:

你也可以有一个自定义的 IDataProtectionProvider 并让所有的 owin 使用它:

You can also have a custom IDataProtectionProvider and have all of owin use that with this:

app.SetDataProtectionProvider(new CustomIDataProtectionProvider());

这篇关于Mono 3.4.1 中的 UserCookieAuthentication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆