问题描述
我有一个项目包括MVC和Web API控制器。我有,
GlobalConfiguration.MessageHandlers.Insert(0,新MessageHandler1());
但是,当我申请一个MVC控制器,它执行这个处理程序。这伤害了我,因为燮pressDefaultHostAuthentication是在MVC要求执行PassiveAuthenticationMessageHandler处理程序。我已经把一个破发点上MessageHandler1.SendAsync,发现System.Web.HttpContext.Current.Handler = {} System.Web.Mvc.MvcHandler其中确认它是MVC的请求。
堆栈跟踪,
MyApp.dll!MyApp.MessageHandler1.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)线120 C#
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.AnonymousMethod__FabricatedMethod5()未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync.AnonymousMethod__0()未知
System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync<System.Net.Http.Htt$p$psponseMessage>(System.Web.Http.Tracing.ITraceWriter traceWriter,System.Net.Http.Htt prequestMessage要求,串类,System.Web.Http.Tracing.TraceLevel水平,串operatorName,串operationName,System.Action&LT; System.Web.Http.Tracing.TraceRecord&GT; beginTrace,System.Func&LT; System.Threading.Tasks.Task&LT; System.Net.Http.Htt presponseMessage&GT;&GT;执行,System.Action&LT; System.Web.Http.Tracing.TraceRecord,System.Net.Http.Htt presponseMessage&GT; endTrace,System.Action&LT; System.Web.Http.Tracing.TraceRecord&GT; errorTrace)未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync(System.Net.Http.Htt$p$pquestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.AnonymousMethod__FabricatedMethod6()未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync.AnonymousMethod__1()未知
System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync<System.Net.Http.Htt$p$psponseMessage>(System.Web.Http.Tracing.ITraceWriter traceWriter,System.Net.Http.Htt prequestMessage要求,串类,System.Web.Http.Tracing.TraceLevel水平,串operatorName,串operationName,System.Action&LT; System.Web.Http.Tracing.TraceRecord&GT; beginTrace,System.Func&LT; System.Threading.Tasks.Task&LT; System.Net.Http.Htt presponseMessage&GT;&GT;执行,System.Action&LT; System.Web.Http.Tracing.TraceRecord,System.Net.Http.Htt presponseMessage&GT; endTrace,System.Action&LT; System.Web.Http.Tracing.TraceRecord&GT; errorTrace)未知
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync(System.Net.Http.Htt$p$pquestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Web.Http.dll!System.Web.Http.HttpServer.AnonymousMethod__FabricatedMethod9()未知
System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync()未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<System.Web.Http.HttpServer.SendAsync>(ref System.Web.Http.HttpServer.SendAsync的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.Start<System.Web.Http.HttpServer.SendAsync>(ref System.Web.Http.HttpServer.SendAsync的statemachine)未知
System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Net.Http.dll!System.Net.Http.HttpMessageInvoker.SendAsync(System.Net.Http.Htt prequestMessage要求,System.Threading.CancellationToken的CancellationToken)未知
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore()未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore>(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore>(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore的statemachine)未知
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore(Microsoft.Owin.IOwinContext背景下,Microsoft.Owin.IOwinRequest owinRequest,Microsoft.Owin.IOwinResponse owinResponse)未知
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.Invoke(Microsoft.Owin.IOwinContext上下文)未知
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke()未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke的statemachine)未知
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke(Microsoft.Owin.IOwinContext上下文)未知
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke()未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke的statemachine)未知
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke的statemachine)未知
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke(Microsoft.Owin.IOwinContext上下文)未知
Microsoft.Owin.dll!Microsoft.Owin.Infrastructure.OwinMiddlewareTransition.Invoke(System.Collections.Generic.IDictionary<string,object>环境)未知
Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(object发件人,发送System.EventArgs,System.AsyncCallback CB,对象extradata)未知
System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()未知
System.Web.dll中!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep步,参考布尔completedSynchronously)未知
System.Web.dll中!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception的错误)未知
System.Web.dll中!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext背景下,System.AsyncCallback CB)未知
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest WR,System.Web.HttpContext上下文)未知
System.Web.dll中!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer,System.IntPtr nativeRequestContext,System.IntPtr moduleData,诠释标志)未知
System.Web.dll中!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer,System.IntPtr nativeRequestContext,System.IntPtr moduleData,诠释标志)未知
[原产于托管过渡]
[托管到本机转换]
System.Web.dll中!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer,System.IntPtr nativeRequestContext,System.IntPtr moduleData,诠释标志)未知
System.Web.dll中!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer,System.IntPtr nativeRequestContext,System.IntPtr moduleData,诠释标志)未知
[AppDomain中转换]
我使用自定义的MessageHandler刚修好它,
GlobalConfiguration.Sup pressDefaultHostAuthentication();
GlobalConfiguration.Filters.Add(新HostAuthenticationFilter(OAuthOptions.AuthenticationType));
GlobalConfiguration.MessageHandlers.Insert(0,新ResetMvcPrincipalMessageHandler()); 公共类ResetMvcPrincipalMessageHandler:DelegatingHandler
{
保护异步覆盖任务其中p型Htt presponseMessage&GT; SendAsync(
HTT prequestMessage请求的CancellationToken的CancellationToken)
{
VAR URL = request.RequestUri.AbsolutePath;
如果(!url.Contains(/ API /))//而不是web API请求
{
VAR本金= request.GetRequestContext()校长。
VAR响应=等待base.SendAsync(请求的CancellationToken);;
request.GetRequestContext()主要=本金。
返回响应;
}
返回等待base.SendAsync(请求的CancellationToken);
}
}
I have a project include MVC and Web API controllers. I have,
GlobalConfiguration.MessageHandlers.Insert(0, new MessageHandler1());
But when I request a MVC controller it executes this handler. It hurting me because SuppressDefaultHostAuthentication is executing PassiveAuthenticationMessageHandler handler on MVC request. I have put a break-point on MessageHandler1.SendAsync and found that System.Web.HttpContext.Current.Handler = {System.Web.Mvc.MvcHandler} which confirm that it is MVC request.
StackTrace,
MyApp.dll!MyApp.MessageHandler1.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Line 120 C#
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.AnonymousMethod__FabricatedMethod5() Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync.AnonymousMethod__0() Unknown
System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync<System.Net.Http.HttpResponseMessage>(System.Web.Http.Tracing.ITraceWriter traceWriter, System.Net.Http.HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, string operatorName, string operationName, System.Action<System.Web.Http.Tracing.TraceRecord> beginTrace, System.Func<System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>> execute, System.Action<System.Web.Http.Tracing.TraceRecord,System.Net.Http.HttpResponseMessage> endTrace, System.Action<System.Web.Http.Tracing.TraceRecord> errorTrace) Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.AnonymousMethod__FabricatedMethod6() Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync.AnonymousMethod__1() Unknown
System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync<System.Net.Http.HttpResponseMessage>(System.Web.Http.Tracing.ITraceWriter traceWriter, System.Net.Http.HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, string operatorName, string operationName, System.Action<System.Web.Http.Tracing.TraceRecord> beginTrace, System.Func<System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>> execute, System.Action<System.Web.Http.Tracing.TraceRecord,System.Net.Http.HttpResponseMessage> endTrace, System.Action<System.Web.Http.Tracing.TraceRecord> errorTrace) Unknown
System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Web.Http.dll!System.Web.Http.HttpServer.AnonymousMethod__FabricatedMethod9() Unknown
System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<System.Web.Http.HttpServer.SendAsync>(ref System.Web.Http.HttpServer.SendAsync stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.Start<System.Web.Http.HttpServer.SendAsync>(ref System.Web.Http.HttpServer.SendAsync stateMachine) Unknown
System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Net.Http.dll!System.Net.Http.HttpMessageInvoker.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore>(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore>(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore stateMachine) Unknown
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore(Microsoft.Owin.IOwinContext context, Microsoft.Owin.IOwinRequest owinRequest, Microsoft.Owin.IOwinResponse owinResponse) Unknown
System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.Invoke(Microsoft.Owin.IOwinContext context) Unknown
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke stateMachine) Unknown
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions>.Invoke(Microsoft.Owin.IOwinContext context) Unknown
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke stateMachine) Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke>(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke stateMachine) Unknown
Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware<Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions>.Invoke(Microsoft.Owin.IOwinContext context) Unknown
Microsoft.Owin.dll!Microsoft.Owin.Infrastructure.OwinMiddlewareTransition.Invoke(System.Collections.Generic.IDictionary<string,object> environment) Unknown
Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(object sender, System.EventArgs e, System.AsyncCallback cb, object extradata) Unknown
System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() Unknown
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) Unknown
System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) Unknown
System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb) Unknown
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr, System.Web.HttpContext context) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
[AppDomain Transition]
I just fix it using custom MessageHandler,
GlobalConfiguration.SuppressDefaultHostAuthentication();
GlobalConfiguration.Filters.Add(new HostAuthenticationFilter(OAuthOptions.AuthenticationType));
GlobalConfiguration.MessageHandlers.Insert(0, new ResetMvcPrincipalMessageHandler());
public class ResetMvcPrincipalMessageHandler : DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var url = request.RequestUri.AbsolutePath;
if (!url.Contains("/api/"))// not web api request
{
var principal = request.GetRequestContext().Principal;
var response = await base.SendAsync(request, cancellationToken);;
request.GetRequestContext().Principal = principal;
return response;
}
return await base.SendAsync(request, cancellationToken);
}
}
这篇关于为什么在MessageHandler的MVC请求被执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!