IHttpModule访问Cookie
public class ACookies: System.Web.IHttpModule, System.Web.SessionState.IRequiresSessionState{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new System.EventHandler(onPreRequestHandlerExecute);
}
public void onPreRequestHandlerExecute(object sender, System.EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context
System.Web.HttpCookie cookie = new System.Web.HttpCookie( "A ");
cookie.Domain = "MySite.com "
DateTime dt = DateTime.Now;
cookie.Expires = dt.AddMinutes(100);
cookie.Values.Add( "USERID ", "123456 ");
context.Response.AppendCookie(cookie);
}
}
}
上面这样好像不能不写入Cookies,同样测试读取Cookies似乎也不能.请问路过大侠有无解决方案?
------解决方案--------------------Cookie应该有用的。
这跟ASP.NET角色授权差不多,Cookie应该起作用的。
------解决方案--------------------我测试了一下,有的啊!
我在global.asax中测试,Cookie使用正常啊
global.asax:
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
System.Web.HttpCookie cookie = new System.Web.HttpCookie( "A ");
DateTime dt = DateTime.Now;
cookie.Expires = dt.AddMinutes(100);
cookie.Values.Add( "USERID ", "123456 ");
System.Web.HttpContext.Current.Response.AppendCookie(cookie);
}
aspx.cs:
if (Request.Cookies[ "A "] != null)
Response.Write(Request.Cookies[ "A "][ "USERID "]);
else
Response.Write( "NO COOKIE ");
------解决方案--------------------http://www.cnblogs.com/zengxi0602/archive/2006/08/16/478634.html
------解决方案--------------------cookie.Domain = "MySite.com "
测试的域名有没有也是MySite.com?
要一样的才行哦
------解决方案--------------------貌似很复杂。