我正在开发.NET Web Api(使用OWIN)和使用Web API的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);
}
我在天蓝色事件日志中发现此错误:
https://microsoft-apiapp08044e6364624e2e88cfda954ace012a.azurewebsites.net:443/job/getemployerjobs/job/getemployerjobs104.45.82.120FalseIIS APPPOOL \ Microsoft-ApiApp08044e6364624e2e88cfda954ace012a108IIS IIS APPPOOL \ Microsoft-ApiApp0802e88(String。布尔替换)在System.Web.HttpHeaderCollection.Set(字符串名称,字符串值)在Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(字符串键,字符串[]值)在Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(字符串键,字符串[]值)在Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2标头,字符串键,String []值)在Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2标头,字符串键,字符串[]值)在Microsoft.Owin.HeaderDictionary.AppendValues(字符串键,字符串[]值)在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider。 b__2(OAuthChallengeContext上下文)在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider.ApplyChallenge(OAuthChallengeContext上下文)在Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.ApplyResponseChallengeAsync()在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler。d__b.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler。 d__8.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationHandler。 d__5.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1。 d__0.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1。 d__0.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Mapping.MapMiddleware。 d__0.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Cors.CorsMiddleware。 d__0.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage。 d__5.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext。 d__2.MoveNext()---从之前引发异常的位置开始的堆栈结束跟踪---在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步骤,布尔值和完成同步)
似乎与Microsoft的OWIN实现有关:http://katanaproject.codeplex.com/discussions/540202。
相关的请求请求在这里:https://katanaproject.codeplex.com/workitem/263
底层OWIN OAuth中间件在创建响应时有时会“封闭”响应。