我尝试让OWin按照Web Api上的热门教程进行操作: http://bitoftech.net/2015/01/21/asp-net-identity-2-with-asp-net-web-api-2-accounts-management/
现在我被困在下面的Getter:
protected AppliationUserManager TengoUserManager
{
get { return _applicationUserManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
}
问题是Request.GetOwinContext()总是返回null。
当我将吸气剂更改为
时 get { return _applicationUserManager ?? System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
一切正常。现在我想知道:
使用HttpContext.Current
代替Request
是否有任何不利之处?
由于HttpContext
具有OwinContext(),但Request
还没有:这是否可通过配置解决?我的Owin-Authentication的启动代码是:
public void Configuration(IAppBuilder app)
{
HttpConfiguration httpConfig=new HttpConfiguration();
app.CreatePerOwinContext(ApplicationContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCors(CorsOptions.AllowAll);
app.UseWebApi(httpConfig);
config.MapHttpAttributeRoutes();
}