配料的WebAPI和委托处理程序

配料的WebAPI和委托处理程序

本文介绍了配料的WebAPI和委托处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的我能得到配料工作...直到某一点。除了注册路线的具体处理程序我也有2委托处理程序

based on my last post I was able to get batching working... until a certain point. In addition to registering the route specific handler I also have 2 delegating handlers


  1. 验证用户

  2. 登录

批量处理穿过处理委派认证用户并记录请求。当messagehandlerinvoker开始发送子/嵌套请求以下异常。

the batch handler goes through the delegating handlers authenticating the user and logging the request. when the messagehandlerinvoker starts to send the child/nested requests the following exception is thrown.

System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'AuthenticationMessageHandler' is not null.
Parameter name: handlers
  Source=System.Net.Http.Formatting
  ParamName=handlers
  StackTrace:
       at System.Net.Http.HttpClientFactory.CreatePipeline(HttpMessageHandler innerHandler, IEnumerable`1 handlers)
       at System.Web.Http.HttpServer.Initialize()
       at System.Web.Http.HttpServer.<EnsureInitialized>b__3()
       at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
       at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
       at System.Web.Http.HttpServer.EnsureInitialized()
       at System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
       at RoutingRequest.Service.Startup.BatchMessageHandler.<>c__DisplayClassd.<PrcoessRequest>b__b(Task`1 m) in C:\CEI\Clients\Footlocker.com\FL - Vendor Routing Portal\source\RoutingRequest.Service\Startup\BatchMessageHandler.cs:line 45
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException:

有我缺少一个配置选项,或者我需要绕过委托处理程序?

is there a config option I am missing, or do I need to bypass the delegating handlers?

修改
这里是我的验证处理程序。

edithere is my authentication handler.

public class AuthenticationMessageHandler
    : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        SetCurrentUser(request);
        return base.SendAsync(request, cancellationToken);
    }

    private void SetCurrentUser(HttpRequestMessage request)
    {
        var values = new List<string>().AsEnumerable();
        if (request.Headers.TryGetValues("routingrequest-username", out values) == false) return;

        var username = values.First();

        var user = Membership.GetUser(username, true);
        if (user == null)
        {
            var message = string.Format("membership information for '{0}' could not be found.", username);
            throw new HttpRequestException(message);
        }

        var roles = Roles.GetRolesForUser(username);

        Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(user.UserName), roles);
    }
}

基于基兰的回答一个子类的httpserver

解决一个问题,并引入了另一个。我的角色提供商获得一个空引用异常。寻找到现在。

based on Kiran's answer a subclassed httpserver fixes one issue and introduces another. My roles provider is getting a null reference exception. looking into that now.

推荐答案

特洛伊就在这里解决此问题的一个伟大的博客:

Troy has a great blog regarding resolving this issue here:

这篇关于配料的WebAPI和委托处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:30