Asp.net Cookies不是持久的

Asp.net Cookies不是持久的,asp.net,cookies,persistence,Asp.net,Cookies,Persistence,我正在使用ASP.net存储cookies。我将cookie保存在代码隐藏(C#)中的弹出窗口中。如果我在弹出窗口关闭之前请求cookie,那么cookie就在那里,但是关闭弹出窗口并返回到其中,在Page_Load事件中查看cookie时,不会显示cookie。我如何让它持续下去 弹出OK按钮中的以下代码 // Set the cookie. this.Response.Cookies["UserData"].Secure = true; this.Response.Cookies["User

我正在使用ASP.net存储cookies。我将cookie保存在代码隐藏(C#)中的弹出窗口中。如果我在弹出窗口关闭之前请求cookie,那么cookie就在那里,但是关闭弹出窗口并返回到其中,在Page_Load事件中查看cookie时,不会显示cookie。我如何让它持续下去

弹出OK按钮中的以下代码

// Set the cookie.
this.Response.Cookies["UserData"].Secure = true;
this.Response.Cookies["UserData"]["UserId"] = iId.ToString();
this.Response.Cookies["UserData"]["UserEmail"] = strEmail;
this.Response.Cookies["UserData"].Expires = DateTime.Now.AddDays(1);
以下代码放置在页面加载事件中

// Get the cookie.
if (null != this.Request.Cookies["UserData"])
{
    // Transmit the cookie information using SSL. Note, the cookie data is still in plain text on the user's computer.
    this.Request.Cookies["UserData"].Secure = true;

    // Extract: Email
    String strEmail = this.Server.HtmlEncode(oPage.Request.Cookies["UserData"]["UserEmail"]);
}
当然,第一次会显示为空,但是随后的加载会显示cookie


我在使用.Values[“Subitem”]=“whatever”时运气稍好一些,但这使基础得以保留,但所有子项都消失了。

一个可能的原因是:您的页面是HTTP,但您将cookie设置为仅HTTPS。所以,浏览器不会将它们与HTTP请求一起发送回您的站点


使用Fiddler(或其他HTTP调试器)查看响应(和下一个请求)中是否正确发送了cookie。

我没有意识到。安全是指https。将cookie存储在非安全模式下是否同时允许http和https访问该cookie?@SarahWeinberger,是的,不标记为“安全”将使它们可以使用http和https。如果您不需要在客户端脚本上访问Cookie,请考虑将其标记为“记住”,这取决于浏览器/接收端来遵守HTTPONE设置。是的,当前的浏览器可以做到这一点;但是,其他可能能够发出http请求的工具不必这样做。