网络API CORS选项仅在Azure上返回500随机 [英] Web API CORS OPTION returns 500 randomly only on azure

查看:327
本文介绍了网络API CORS选项仅在Azure上返回500随机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯开发一个.NET的Web API(使用OWIN)和灰烬的应用程序使用Web API。该网站的API托管在蔚蓝(API应用程序)。问题是,有时选项调用失败(500错误)和GUI挂起。如果我再次触发选项调用它的作品了。如果进出口运行在我的本地IIS的API,这个问题永远不会发生。当我没有做任何事情/引发了Web应用程序一段时间(5分钟)任何Ajax调用最常发生的问题。任何线索为什么会这样?

这是我的启动配置:

 公共部分类
    启动
{
    公共无效配置(IAppBuilder应用程序)
    {
        //启用CORS
        app.UseCors(CorsOptions.AllowAll);


        //使迟发型
        Hangfire.GlobalConfiguration.Configuration
            .UseSqlServerStorage(的DbConnection)
            .UseActivator(新StructureMapJobActivator(IoC.Initialize()));

        app.UseHangfireDashboard();
        app.UseHangfireServer();

        // automapper
        AutoMapperBootstrapper.Bootstrap();

        // OAuth的2
        VAR的UserManager =新的UserManager();

        VAR项AuthConfig =新SentinelAuthorizationServerOptions()
            {
                的UserManager =的UserManager,
                ClientManager =新ClientManager()
            };

        VAR shaProvider =新SHA2CryptoProvider();

        VAR onBoardTokenRepository =新OnBoardTokenRepository(新连接工厂(新配置())的DbConnection);
        authConfig.TokenManager =新TokenManager(LogManager.GetLogger<启动>()的UserManager,新PrincipalProvider(shaProvider),shaProvider,新TokenFactory(),onBoardTokenRepository);

        app.UseSentinelAuthorizationServer(项AuthConfig);

        GlobalConfiguration.Configure(WebApiConfig.Register);
    }
 

我发现,在蔚蓝的事件日志此错误:

   https://microsoft-apiapp08044e6364624e2e88cfda954ace012a.azurewebsites.net:443/job/getemployerjobs/job/getemployerjobs104.45.82.120FalseIIS APPPOOL \微软ApiApp08044e6364624e2e88cfda954ace012a108IIS APPPOOL \微软ApiApp08044e6364624e2e88cfda954ace012aFalse在System.Web.HttpHeaderCollection.SetHeader(字符串名称,字符串值,布尔替换)
   在System.Web.HttpHeaderCollection.Set(字符串名称,字符串值)
   在Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(字符串键的String []值)
   在Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(字符串键的String []值)
   在Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2头,串键,的String []值)
   在Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2头,串键,的String []值)
   在Microsoft.Owin.HeaderDictionary.AppendValues​​(字符串键的String []值)
   在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.<.ctor>b__2(OAuthChallengeContext上下文)
   在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.ApplyChallenge(OAuthChallengeContext上下文)
   在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.ApplyResponseChallengeAsync()
   在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseCoreAsync>d__b.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseAsync>d__8.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler&LT; TeardownAsync&GT; d__5.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1&LT;调用&GT; d__0.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1&LT;调用&GT; d__0.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Mapping.MapMiddleware&LT;调用&GT; d__0.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Cors.CorsMiddleware&LT;调用&GT; d__0.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__5.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务的任务)
   在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务的任务)
   在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__2.MoveNext()
---从previous位置的堆栈跟踪,其中引发异常的结束---
   在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult的AR)
   在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult的AR)
   在System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔和放大器; completedSynchronously)

解决方案

看来,这是关系到微软OWIN实现: HTTP://katanaproject.$c$cplex.com/discussions/540202

有关拉请求是在这里:的https://katanaproject.$c$cplex.com /工作项/ 263

底层OWIN OAuth的中间件有时封堵时,它会创建一个响应的响应。

Im developing a .NET Web Api (using OWIN) and a ember app consuming the web api. The web api is hosted on azure (api app). The problem is that sometimes the option call is failing (500 error) and the gui hangs. If I triggers the option call again it works again. If Im running the api on my local IIS, this problem never happens. The problem occurs most often when I have not done anything/triggered any ajax calls in the web app for awhile (5 min). Any clue why this is happening?

This is my startup config:

public partial class
    Startup
{
    public void Configuration(IAppBuilder app)
    {
        //enable cors
        app.UseCors(CorsOptions.AllowAll);


        //enable hangfire
        Hangfire.GlobalConfiguration.Configuration
            .UseSqlServerStorage("DbConnection")
            .UseActivator(new StructureMapJobActivator(IoC.Initialize()));

        app.UseHangfireDashboard();
        app.UseHangfireServer();

        //automapper
        AutoMapperBootstrapper.Bootstrap();

        //oauth 2
        var userManager = new UserManager();

        var authConfig = new SentinelAuthorizationServerOptions()
            {
                UserManager = userManager,
                ClientManager = new ClientManager(),
            };

        var shaProvider = new SHA2CryptoProvider();

        var onBoardTokenRepository = new OnBoardTokenRepository(new ConnectionFactory(new Configuration()), "DbConnection");
        authConfig.TokenManager = new TokenManager(LogManager.GetLogger<Startup>(), userManager, new PrincipalProvider(shaProvider), shaProvider, new TokenFactory(), onBoardTokenRepository);

        app.UseSentinelAuthorizationServer(authConfig);

        GlobalConfiguration.Configure(WebApiConfig.Register);
    }

I found this error in the azure event log:

   https://microsoft-apiapp08044e6364624e2e88cfda954ace012a.azurewebsites.net:443/job/getemployerjobs/job/getemployerjobs104.45.82.120FalseIIS APPPOOL\Microsoft-ApiApp08044e6364624e2e88cfda954ace012a108IIS APPPOOL\Microsoft-ApiApp08044e6364624e2e88cfda954ace012aFalse   at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace)
   at System.Web.HttpHeaderCollection.Set(String name, String value)
   at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key, String[] values)
   at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(String key, String[] value)
   at Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
   at Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
   at Microsoft.Owin.HeaderDictionary.AppendValues(String key, String[] values)
   at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.<.ctor>b__2(OAuthChallengeContext context)
   at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.ApplyChallenge(OAuthChallengeContext context)
   at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.ApplyResponseChallengeAsync()
   at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseCoreAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.<TeardownAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Cors.CorsMiddleware.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
   at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
   at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

解决方案

It seems this is related to Microsofts OWIN implementation: http://katanaproject.codeplex.com/discussions/540202 .

The relevant pull request is here: https://katanaproject.codeplex.com/workitem/263

The underlying OWIN OAuth middleware sometimes "seals off" the response when it creates a response.

这篇关于网络API CORS选项仅在Azure上返回500随机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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