代码之家  ›  专栏  ›  技术社区  ›  Mohammad Dayyan

访问Unity WebApi2 C#?中的请求头?

  •  0
  • Mohammad Dayyan  · 技术社区  · 6 年前

    我想创造一个 RegisterType 基于Unity中的请求头,C#。

    var container = new UnityContainer();
    container.RegisterType<OrganizationServiceProxy>(new InjectionFactory(unityContainer =>
    {
        var request = HttpContext.Current.Request; //Exception 'Request is not available in this context
        const string errorMessage = "Please add `CrmType` key to header to specify CRM type";
        var crmTypeString = request.Headers["CrmType"];
        .
        .
        .
        return new SOmeObject(crmTypeString );
    }));
    

    但发生了以下异常:
    Request is not available in this context

    如何在Unity5.2.0中访问请求头。

    0 回复  |  直到 6 年前