MVC3 在过滤器中使用cookie为何无法存入请求中
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SportWebControl.Base
{
public class BaseAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
return base.AuthorizeCore(httpContext);
}
public override void OnAuthorization(AuthorizationContext filterContext)
{
HttpCookie cookie = new HttpCookie("Web_Language");
cookie.Expires = DateTime.MaxValue;
cookie.Value = "C";
HttpContext.Current.Response.AppendCookie(cookie);
base.OnAuthorization(filterContext);
}
}
}
cookie却读取不到! mvc3 cookie 过滤器 --------------------编程问答-------------------- 写法没问题,过滤器都加到了controller上面了没有?也就是你调试进来cookie写入了吗?
然后你获取cookie的代码能贴一下吗? --------------------编程问答-------------------- public class LoginAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext.HttpContext == null)
throw new ArgumentNullException("filterContext.HttpContext is null!");
if (filterContext.HttpContext.Session == null)
throw new ArgumentNullException("filterContext.HttpContext.Session is null!");
HttpCookie cookie = filterContext.RequestContext.HttpContext.Request.Cookies["Web_Language"];
}
}
有时候这个 HttpContext == null
这是接收代码!
补充:.NET技术 , ASP.NET