如何从ActionFilterAttribute上下文中获取cookie值?
actionContext.Request.Cookies下没有Cookie。 并且无法在Request对象下找到任何Cookie。
using System;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace MapManager.Helpers
{
public class CheckCsrfHeaderAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (actionContext.Request.Method == System.Net.Http.HttpMethod.Post
|| actionContext.Request.Method == System.Net.Http.HttpMethod.Put
|| actionContext.Request.Method == System.Net.Http.HttpMethod.Delete)
{
//GetCookies does not exist
var cookie = actionContext.Request.Headers.GetCookies("XSRF-TOKEN").FirstOrDefault();
答案 0 :(得分:0)
HttpRequestHeadersExtensions.GetCookies位于System.Net.Http中, 所以必须包括System.Net.Http