简体   繁体   English

我应该在哪里存储Cookie?

[英]Where should I store a cookie?

I have a WPF app that talks to a web server. 我有一个与Web服务器通信的WPF应用程序。 It needs to save a session cookie when it closes for subsequent use. 它需要在关闭时保存会话cookie,以备后用。 What is the right way to do this? 什么是正确的方法? I could put it in a config file, isolated storage, or a plain text file but I don't want to re-invent the wheel. 我可以将其放在配置文件,独立存储或纯文本文件中,但我不想重新发明轮子。

Where are you storing user settings now for your application? 您现在在哪里存储应用程序的用户设置? I would probably choose the same area. 我可能会选择同一区域。

If no area is currently specified, probably an application settings file (user.config) is the best spot for it. 如果当前未指定区域,则最好使用应用程序设置文件(user.config)。

Settings is easy to use. Settings易于使用。 You simply define a setting of type List<Cookie> and then you use it like so: 您只需定义类型为List<Cookie>的设置,然后按如下方式使用它:

public List<Cookie> Cookies {
    get {
        return Settings.Default.Cookies;
    }
    set {
        Settings.Default.Cookies = value;
        Settings.Default.Save();
    }
}

Of course, you'd need to define the type Cookie . 当然,您需要定义Cookie类型。

To create the setting, go to your application properties (right click the project and select properties), then go to the Settings tab. 要创建设置,请转到应用程序属性(右键单击项目并选择属性),然后转到“设置”选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM