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

时间:2019-02-02 16:12:07

标签: c# asp.net-web-api2 unity-container

我想基于Unity C#中的请求标头创建一个RegisterType

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

如何通过Web访问Unity 5.2.0中的请求标头。

0 个答案:

没有答案
相关问题