gpt4 book ai didi

asp.net-mvc - WebApp-WebAPI-OpenIDConnect-DotNet 未部署在 azure 上

转载 作者:行者123 更新时间:2023-12-03 03:14:54 26 4
gpt4 key购买 nike

我已经创建了WebApp-WebAPI-OpenIDConnect-DotNet的示例项目。引用项目可在 git 上找到。 .

我按照 git repo 上描述的所有步骤进行操作。我的示例项目在本地主机上正常运行。但是当我在 Azure 上部署项目时,出现以下错误。

请检查下面的堆栈跟踪。

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
CMS.Web.Utils.NaiveSessionCache.Load() in c:\a\src\CMS.Web\CMS.Web\Utils\NaiveSessionCache.cs:30
CMS.Web.Utils.NaiveSessionCache..ctor(String userId) in c:\a\src\CMS.Web\CMS.Web\Utils\NaiveSessionCache.cs:23
CMS.Web.Startup.<ConfigureAuth>b__2(AuthorizationCodeReceivedNotification context) in c:\a\src\CMS.Web\CMS.Web\App_Start\Startup.Auth.cs:83
Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +4995
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +6529
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Security.Infrastructure.<BaseInitializeAsync>d__0.MoveNext() +595
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +264
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +191
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +665
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +191
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +189
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

最佳答案

我正在处理一个相同的案例。我的项目正在开发环境上工作,并在将其发布到生产环境后在同一行上获取 NullRefenceException 。经过研究后,我发现 Request.Current 没问题,但 Request.Current.Session 为空。所以,我将代码更改为这样:

public void Load()
{
lock (FileLock)
{
if (HttpContext.Current != null && HttpContext.Current.Session != null)
{

if (HttpContext.Current.Session[CacheId] == null)
throw new System.NullReferenceException("CacheId is null");

Deserialize((byte[]) HttpContext.Current.Session[CacheId]);
}
}
}

之后,它给我 WebExcetpion 400(错误请求),这是在创建 session 之前发生的。

为了处理这种错误,我更改了 Startup.Auth.cs:

                Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = OnAuthenticationFailed,
...
}

然后:

   private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
{
UtilLogger.PublishException(notification.Exception);

notification.HandleResponse();
notification.Response.Redirect($"{postLogoutRedirectUri}?message={notification.Exception.Message}");
return Task.FromResult(0);
}

关于asp.net-mvc - WebApp-WebAPI-OpenIDConnect-DotNet 未部署在 azure 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29715629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com