老大们,我想读写和删cookies,网上搜索了一段代码,却死活不会用(基础太差了,初学。。不好意思)。
能不能请你写出来调用的代码呀?
谢谢!
public void WriteCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue,
string TextValue, int ExpriesHour)
{
response.Cookies[IndexValue].Value = TextValue;
response.Cookies[IndexValue].Expires = DateTime.Now.AddHours(ExpriesHour);
} public string ReadCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue)
{
if (request.Cookies[IndexValue] != null)
return request.Cookies[IndexValue].Value;
return "";
} public void DeleteCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue)
{
if (request.Cookies[IndexValue] != null)
{
HttpCookie cookies = request.Cookies[IndexValue];
cookies.Expires = DateTime.Now.AddHours(-1);
response.Cookies.Add(cookies);
}
}
能不能请你写出来调用的代码呀?
谢谢!
public void WriteCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue,
string TextValue, int ExpriesHour)
{
response.Cookies[IndexValue].Value = TextValue;
response.Cookies[IndexValue].Expires = DateTime.Now.AddHours(ExpriesHour);
} public string ReadCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue)
{
if (request.Cookies[IndexValue] != null)
return request.Cookies[IndexValue].Value;
return "";
} public void DeleteCookies(HttpResponse response, HttpRequest request, HttpServerUtility server, string IndexValue)
{
if (request.Cookies[IndexValue] != null)
{
HttpCookie cookies = request.Cookies[IndexValue];
cookies.Expires = DateTime.Now.AddHours(-1);
response.Cookies.Add(cookies);
}
}
解决方案 »
- 有点疑惑。取网卡的MAC
- C#代码保存Excel成功,但是出现一个Excel进程,每次都要手动结束
- CheckBoxList 选中问题
- 动态导入图片的问题,请高人指点。急!
- 无法引用system.io,提示找不到类型或命名空间名称,如何解决
- 求几个简单的正则表达式,望正则表达式高手帮助
- 对于C#你用的是2005还是2003?
- 怎么用一个string类型的变量当作一个控件的名称用
- 散分,c#的作注释的有多少方法!!
- 提示问题!菜鸟问题马上送分
- C# 读取 excel中的 数字 的 时候,提示错误 “ 数字必须介于 1 和 32767 之间“
- 英文模糊用select * from 表 where 字段 like '%" textbox.text "%' 查不出带有英文逗号 中括号
newcookie.Values["username"] = "";
newcookie.Values["password"] = "";
newcookie.Expires = DateTime.Now.AddDays(15);
Response.AppendCookie(newcookie);
System.Web.HttpCookie cookie = Request.Cookies["user"];
if (cookie != null)
{
cookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Set(cookie);
}HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookiename];
if (cookie != null)
{
cookie.Values.Clear();
SetUserCookieExpireTime(cookiename, -1);
cookie.Domain = _domain;
System.Web.HttpContext.Current.Response.Cookies.Set(cookie);
}
public static void SetUserCookieExpireTime(string key, int days)
{
System.Web.HttpContext.Current.Response.Cookies[key].Domain = _domain;
System.Web.HttpContext.Current.Response.Cookies[key].Path = _cookiepath;
System.Web.HttpContext.Current.Response.Cookies[key].Expires = DateTime.Now.AddDays(days);
}
Response.Write(value);DeleteCookies(Response, Request, Server, "username");