2015-06-21 48 views
1

我正在開發一個.NET Web Api(使用OWIN)和一個使用Web API的應用程序應用程序。 web api託管在azure(api應用程序)上。問題是,有時候選項調用失敗(500錯誤)並且gui掛起。如果我再次觸發選項呼叫,它將再次起作用。如果我在本地IIS上運行api,這個問題從未發生過。這個問題最常發生在我沒有做任何事情/在Web應用程序中觸發任何ajax調用一段時間(5分鐘)。任何線索爲什麼會發生這種情況?Web API CORS OPTION只能在azure上隨機返回500個

這是我的啓動配置:

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); 
    } 

我發現這個錯誤在蔚藍的事件日誌:

 
    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) 

+0

「OAuthBearerAuthenticationProvider」中的構造函數在響應中添加了一個「WWW-Authenticate」標頭。請參閱http://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Security.OAuth/Provider/OAuthBearerAuthenticationProvider.cs 但這只是堆棧跟蹤。異常消息將有助於確定實際的錯誤是什麼。 – azzlack

+0

在事件日誌中發現此消息:服務器在發送HTTP標頭後無法追加標頭 – oskarkvamme

回答