Cookie和C#程序的会话 [英] cookies and session for C# program

查看:81
本文介绍了Cookie和C#程序的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我有2个问题

1-我可以在Windows窗体项目的C#程序(即不是ASP或Web)上使用cookie和会话吗?

2-我的程序中需要Cookie才能记住用户
我必须使用哪个(cookie或会话)?

Thanks

解决方案

为什么要在桌面应用程序中使用Cookie和显式会话?它们是一种通过无状态协议(HTTP)模拟持久性应用程序的机制,在真正的持久性应用程序中它们并不是必需的.如果对象处于范围内,则您设置的任何状态(例如,对象的属性或字段)都将保留在那里,直到处理结束.

假设您真正要问的是我应该如何存储状态信息?":我通常有一个用于存储应用程序数据的存储库(仅在主窗体上,或者在单独的类中,在某个地方带有静态引用,具体取决于应用程序的复杂性),并创建UI控件作为数据对象某些部分上的视图(使用数据绑定或视图模型).如果您希望能够加载,保存或记住状态,则需要使数据对象可串行化(我并不是说[Serializable]一定是可串行的,而是提供了一些往返字节流的机制).

嗨!
您可以使用静态变量重新输入Cookie,并在C#程序窗口中添加.
如果您想记住用户,则可以使用C#中的文件库来创建包含用户的文件.
祝你好运!


U必须使用cookie ...

ASP.NET Cookie入门指南 [ ^ ]
我希望这将是有用的...


hello
I have 2 question

1 - can I use cookies and session for C# program (i.e not ASP or web) its windows form project ?

2 - I need cookies in my program to remember the user
which I have to use ( cookies or session ) ?

thanks

解决方案

Why would you want to use cookies and an explicit session in a desktop app? They are a mechanism for emulating a persistent application over a stateless protocol (HTTP), and they''re just not necessary within a genuinely persistent application. Any state that you set (e.g. properties or fields on objects) will remain there until the end of the process, if the object stays in scope.

Assuming what you''re really asking is ''how should I store state information?'': I usually have a single repository for application data (either just on the main form or in a separate class with a static reference somewhere, depending on the complexity of the application), and create UI controls as views on some part of the data object (either using data binding or view-models). If you want to be able to load, save or remember state, you need to make the data object serialisable (I don''t mean [Serializable] necessarily, but providing some mechanism of translating to/from byte streams).


Hi !
You can use the static variable retype cookie, seession in C# program windows.
If you want remember the user, you can use File libraries in C# to create file contains the users.
Goodluck !


U have to use the cookies...

Beginner''s Guide to ASP.NET Cookies[^]
I hope tis would be useful...


这篇关于Cookie和C#程序的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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