在自托管的WebAPI获取的Htt prequest背景 [英] Getting HttpRequest context in self-hosted WebApi
问题描述
我如何从托管MVC的WebAPI?自进入查询字符串
How can I access the query string from a self hosted MVC WebAPI?
呼吁下面失败,NRE,因为当前是空的(亦称空)
Call to the following failed with NRE, because Current is empty (aka. null)
System.Web.HttpContext.Current.Request["myQuery"]
我需要在控制器外部访问当前的背景下,因为我想通过控制我的对象实例化。 DI。例如:
I need access to the current context outside of the controller, since I want to control my object instantiation via. DI. eg.
container
.RegisterType<MyObject>(
new InjectionFactory(
uc =>
new MyObject(
System.Web.HttpContext.Current.Request["myParam"]) //This failed.
));
呼吁 container.Resolve&LT;为MyObject&GT;从ControllerApi code里面()
失败,因为上面的NRE
Call to container.Resolve<MyObject>()
from inside the ControllerApi code failed, because of the above NRE.
推荐答案
HttpContext.Current不可自托管的项目
HttpContext.Current isn't available in self hosted projects
请参见:<一href=\"http://stackoverflow.com/questions/11347807/httpselfhostserver-and-httpcontext-current\">HttpSelfHostServer和HttpContext.Current
这篇关于在自托管的WebAPI获取的Htt prequest背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!