如何做饼干在ASP.NET工作? [英] How do Cookies Work in ASP.NET?

查看:113
本文介绍了如何做饼干在ASP.NET工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站,我的工作是由几个项目了(写在几种语言)。现在,我们必须使用查询字符串和会话变量有些别扭code,以保持登录时,他们从项目到项目去的人。由于Cookie是特定我们正试图转换到他们,因为他们可以使用使用不同语言的一种语言又由不同的项目(在同一个域)访问一个项目进行设置的域。

The website where I work is made up of several projects (written in several languages). Right now we have to use some awkward code in query strings and session variables to keep a person logged in when they go from project to project. Since cookies are domain specific we're trying to convert to them since they can be set in one project using one language yet be accessed by a different project (on the same domain) using a different language.

不过我有改变cookie的值,并删除这些问题。或者更具体的,我有我有做出一个cookie棍子任何更改的麻烦。

However I am having problems changing the value of a cookie and deleting them. Or to be more specific, I'm having trouble having any changes I make to a cookie stick.

例如在我的注销code:

For example in my logout code:

if (Request.Cookies["thisuserlogin"] != null)
{
    HttpCookie myCookie = new HttpCookie("thisuserlogin");
    myCookie.Value = String.Empty;
    myCookie.Expires = DateTime.Now.AddDays(-1d);
    Response.Cookies.Add(myCookie);
    Response.Cookies.Set(myCookie);
    litTest.Text = myCookie.Expires.ToString() + "<br />" + Request.Cookies["thisuserlogin"].Expires.ToString();
}

我风与一行是昨天和下一行是1/1/0001 12:00:00即使他们应该是相同的cookie。那么,为什么即使cookie的设置,它的价值并没有改变?有没有办法强制用户的电脑更新cookie的值,包括删除?

I wind up with one line being yesterday and the next line being 1/1/0001 12:00:00 even though they SHOULD be the same cookie. So why is it that even though the cookie was set, it's value did not change? Is there a way to force the user's computer to update a cookie's value, including deletion?

非常感谢你。
PS你可以提供给一个易于理解的底漆饼干将AP preciated的网址。

Thank you very much. PS Any URLs you can provide to give an easy-to-understand primer for cookies would be appreciated.

推荐答案

http://msdn.microsoft.com/en-us/library/ms178194(v = VS.100)的.aspx

if (Request.Cookies["thisuserlogin"] != null)
{
    HttpCookie byeCookie = new HttpCookie("thisuserlogin");
    byeCookie.Expires = DateTime.Now.AddDays(-1);
    Response.Cookies.Add(byeCookie);

    // Update Client
    Response.Redirect(Request.RawUrl);
}

这篇关于如何做饼干在ASP.NET工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆