gpt4 book ai didi

asp.net - 从 AuthorizeAttribute 过滤器中获取 cookie

转载 作者:行者123 更新时间:2023-12-04 23:50:14 24 4
gpt4 key购买 nike

使用 ASP.Net Web API 2,是否可以从 AuthorizeAttribute 过滤器中获取 cookie

public class SessionFilter : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
// I need to read cookie values here
// filterContext.??getCookies??

}

}

最佳答案

从 AuthorizationContext 获取 cookie:

filterContext.HttpContext.Request.Cookies

方法中的示例:
public class SessionFilter : AuthorizeAttribute

{
public override void OnAuthorization(AuthorizationContext filterContext)
{
// I need to read cookie values here
HttpCookie cookie = filterContext.HttpContext.Request.Cookies.Get("Cookie Name");
}

}

关于asp.net - 从 AuthorizeAttribute 过滤器中获取 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24248293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com