ASP.NET VNext Request.Properties
本文关键字:Properties Request VNext NET ASP | 更新日期: 2023-09-27 18:13:34
在以前的MVC版本中,我使用这样的身份验证服务
public class OvAuthorizeAttribute : FilterAttribute
{
public async Task<HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func<Task<HttpResponseMessage>> continuation)
{
..........
var user = await ContainerFactory.Container.GetInstance<IMembershipService>().GetUser(token);
if (user == null)
........
actionContext.Request.Properties["User"] = user;
}
}
[OvAuthorize]
public class CommonController : Controller
{
public User CurrentUser
{
get
{
return Request.Properties["User"] as User; //ERROR
}
}
}
但是现在,我不能访问请求。新控制器定义中的属性
您可以直接从Controller
实例获得User
。下面的属性在Controller上是公开的。
/// <summary>
/// Gets or sets the <see cref="ClaimsPrincipal"/> for user associated with the executing action.
/// </summary>
public ClaimsPrincipal User
{
get
{
return Context?.User;
}
}