InternetSetCookie does not store cookie in Temporary Internet Files

孤人 提交于 2019-12-08 04:50:46

问题


I'm trying to create a cookie on client side using wininet from a c# winform application. So I use this code:

[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]  
public static extern bool InternetSetCookie
(
    string lpszUrlName, 
    string lbszCookieName, 
    string lpszCookieData
);

private void btnRestaure_Click(object sender, EventArgs e)
{
    try
    {
        var result = InternetSetCookie("www.mydomain.com", "MyCookie",
                              "value=helloworld");
    }
    catch(Exception ex)
    {

    }
}

InternetSetCookie returns me true but I can't find the cookie in the Temporary Internet Files folder. Any clue ?


回答1:


I think if you don't specify an expiration date then you create a session cookie. If you want a persistent cookie try specifying an expiration date.

I assume that such a cookie is only stored in RAM and not serialized to disk. And most likely only visible to your own process.


If you check the MSDN documentation for InternetSetCookie you see:

Cookies created by InternetSetCookie without an expiration date are stored in memory and are available only in the same process that created them. Cookies that include an expiration date are stored in the windows\cookies directory.



来源:https://stackoverflow.com/questions/5390989/internetsetcookie-does-not-store-cookie-in-temporary-internet-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!