为什么[Owin]在新项目上引发null异常? [英] Why is [Owin] throwing a null exception on new project?

查看:69
本文介绍了为什么[Owin]在新项目上引发null异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题,我不确定如何解决,或者我什至不能解决.

I have a rather strange issue i'm not sure how to fix or if i can even fix it.

我已经对该问题进行了一些研究,但找不到导致问题的答案.

I've done some research into the issue but can't find an answer to what's causing it.

我正在 http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-和google-oauth2-和openid登录

,并在启用 SSL 并将 controller 更改为要求https后,出现以下错误:

and after enabling SSL and changing the controller to require https i get the following error:

"/"应用程序中的服务器错误.

Server Error in '/' Application.

对象引用未设置为对象的实例.

Object reference not set to an instance of an object.

描述:执行以下操作时发生未处理的异常 当前的Web请求.请查看堆栈跟踪以获取更多信息 有关错误及其在代码中起源的信息.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.NullReferenceException:没有对象引用 设置为对象的实例.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

源错误:

在执行过程中生成了未处理的异常 当前的Web请求.有关原产地和位置的信息 可以使用下面的异常堆栈跟踪来识别异常.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

堆栈跟踪:

[NullReferenceException:对象引用未设置为的实例 对象.]
Microsoft.Owin.Security.Cookies.CookieAuthenticationProvider.Exception(CookieExceptionContext 上下文)+49
Microsoft.Owin.Security.Cookies.d__2.MoveNext() +3698 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +810 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext()+427 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext()+641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext()+641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext()+641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +287 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +272 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+22 Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow()+33 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)+150
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)+42
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和已完成同步)+155

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Owin.Security.Cookies.CookieAuthenticationProvider.Exception(CookieExceptionContext context) +49
Microsoft.Owin.Security.Cookies.d__2.MoveNext() +3698 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +810 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +427 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.AspNet.Identity.Owin.d__0.MoveNext() +641 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +287 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +272 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22 Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow() +33 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +150
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +42
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.34237

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

关闭SSL可以解决此问题,我也知道注释掉app_start中的 startup.auth 可以解决SSL上的问题.

Turning off SSL fixes the issue, I also know that commenting out the startup.auth in app_start fixes the issue on SSL.

有人知道为什么会这样吗?

推荐答案

类似于Sandeep的答案,我还更新了cookie身份验证提供程序.除此之外,我没有吞下错误,而是抛出了异常,因此您可以了解潜在的问题是什么:

Similar to Sandeep's answer, I also updated the cookie authentication provider. Except, instead of swallowing the error I threw the exception so you could see what the underlying problem was:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
        // Enables the application to validate the security stamp when the user logs in.
        // This is a security feature which is used when you change a password or add an external login to your account.  
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
            validateInterval: TimeSpan.FromMinutes(30),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),

            /* I changed this part */
            OnException = (context =>
            {
                throw context.Exception;
            })
    }                
});

对我来说,潜在的问题是我更改了模型并忘记添加新的迁移.

The underlying problem for me was that I had changed the model and forgotten to add a new migration.

这篇关于为什么[Owin]在新项目上引发null异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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