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)
“OAuthBearerAuthenticationProvider”中的构造函数在响应中添加了一个“WWW-Authenticate”标头。请参阅http://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Security.OAuth/Provider/OAuthBearerAuthenticationProvider.cs 但这只是堆栈跟踪。异常消息将有助于确定实际的错误是什么。 – azzlack
在事件日志中发现此消息:服务器在发送HTTP标头后无法追加标头 – oskarkvamme