Ajax Web API CORS选项仅在azure上随机返回500

Ajax Web API CORS选项仅在azure上随机返回500,ajax,azure,asp.net-web-api,azure-api-apps,Ajax,Azure,Asp.net Web Api,Azure Api Apps,我正在开发一个.NETWebAPI(使用OWIN)和一个使用WebAPI的ember应用程序。web api托管在azure(api应用程序)上。问题是,有时选项调用失败(500错误),gui挂起。如果我再次触发选项调用,它将再次工作。如果我在本地IIS上运行api,这个问题永远不会发生。当我有一段时间(5分钟)没有在web应用程序中执行任何操作/触发任何ajax调用时,问题最常出现。你知道为什么会这样吗 这是我的启动配置: public partial class Startup {

我正在开发一个.NETWebAPI(使用OWIN)和一个使用WebAPI的ember应用程序。web api托管在azure(api应用程序)上。问题是,有时选项调用失败(500错误),gui挂起。如果我再次触发选项调用,它将再次工作。如果我在本地IIS上运行api,这个问题永远不会发生。当我有一段时间(5分钟)没有在web应用程序中执行任何操作/触发任何ajax调用时,问题最常出现。你知道为什么会这样吗

这是我的启动配置:

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);
    }
公共部分类
启动
{
公共无效配置(IAppBuilder应用程序)
{
//启用cors
应用程序UseCors(CorsOptions.AllowAll);
//启用hangfire
Hangfire.GlobalConfiguration.Configuration
.UseSqlServerStorage(“数据库连接”)
.UseActivator(新结构MapJobActivator(IoC.Initialize());
app.UseHangfireDashboard();
app.UseHangfireServer();
//汽车制造商
AutoMapperBootstrapper.Bootstrap();
//oauth 2
var userManager=new userManager();
var authConfig=new sentinelauauthorizationserveroptions()
{
UserManager=UserManager,
ClientManager=新的ClientManager(),
};
var shaProvider=新的SHA2CryptoProvider();
var onBoardTokenRepository=newonboardtokenrepository(newconnectionfactory(new Configuration()),“DbConnection”);
authConfig.TokenManager=new-TokenManager(LogManager.GetLogger()、userManager、new-PrincipalProvider(shaProvider)、shaProvider、new-TokenFactory()、onBoardTokenRepository);
app.UseSentinelAuthorizationServer(authConfig);
GlobalConfiguration.Configure(WebApiConfig.Register);
}
我在azure事件日志中发现此错误:

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) https://microsoft-apiapp08044e6364624e2e88cfda954ace012a.azurewebsites.net:443/job/getemployerjobs/job/getemployerjobs104.45.82.120FalseIIS APPPOOL\Microsoft-APIAPP08044E636424E2E88CFDA954ACE012A108IIS APPPOOL\Microsoft-APIAPP08044E636424E2E88CFDA954ACE012AFALSE位于System.Web.HttpHeaderCollection.SetHeader(字符串名称、字符串值、布尔替换) 位于System.Web.HttpHeaderCollection.Set(字符串名称、字符串值) 位于Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(字符串键,字符串[]值) 位于Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_项(字符串键,字符串[]值) 位于Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2头,字符串键,字符串[]值) 位于Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2头,字符串键,字符串[]值) 位于Microsoft.Owin.HeaderDictionary.AppendValues(字符串键,字符串[]值) 位于Microsoft.Owin.Security.OAuth.oauthBeareAuthenticationProvider.b_uu2(OAuthChallengeContext) 位于Microsoft.Owin.Security.OAuth.OAuthBeareAuthenticationProvider.ApplyChallenge(OAuthChallengeContext) 在Microsoft.Owin.Security.OAuth.OAuthBeareAuthenticationHandler.ApplyResponseChallengeAsync()上 在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.d_ub.MoveNext()中 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.d_u8.MoveNext()中 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.d_u5.MoveNext()中 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d_u0.MoveNext()上 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.d_u0.MoveNext()上 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Mapping.MapMiddleware.d_u0.MoveNext()中 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Cors.CorsMiddleware.d_u0.MoveNext()上 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.d_u5.MoveNext()中 ---来自引发异常的上一个位置的堆栈结束跟踪--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中 在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d_u2.MoveNext()中 ---上一个位置w的堆栈结束跟踪