Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get cookies from AuthorizeAttribute Filter

Using ASP.Net Web API 2, is it possible to get cookies from the AuthorizeAttribute filter

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

     }

}
like image 213
Ishikawa91 Avatar asked Feb 13 '23 17:02

Ishikawa91


1 Answers

To get the cookies from AuthorizationContext:

filterContext.HttpContext.Request.Cookies

Example in the method:

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");    
     }

}
like image 130
Ishikawa91 Avatar answered Feb 16 '23 04:02

Ishikawa91