【发布时间】:2014-04-29 08:52:19
【问题描述】:
我需要在 ASP.NET WEB API AuthorizeAttribute 中获取当前的 HttpContextBase。
如何从被覆盖的 IsAuthorized() 中的 HttpActionContext 参数中获取?
protected override bool IsAuthorized(HttpActionContext actionContext)
{
// need to call code that requires the current Controllers HttpContextBase
}
【问题讨论】:
-
你不能用
HttpContext.Current吗? -
不。需要支持 TDD。
-
HttpContext 不是 Web API 的一部分,您要查找的实际信息是什么。
-
@DarrelMiller,您能否提供支持该声明的参考资料?我需要在我的 AuthorizeAttribute 中阅读自定义请求标头。问题解决了,看答案。
-
@Magnus 尝试在自托管下运行您的 Web API。不会有静态的HttpContext。请求标头位于请求对象上,该对象是 HttpActionContext 的一个属性。
标签: asp.net-web-api