如何在Windows应用程序中使用会话 [英] How to use session in windows application

查看:99
本文介绍了如何在Windows应用程序中使用会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是使用c#的Windows应用程序.如何设置会话?我输入了Session["Time"]=DateTime.Now;.但是错误是这样的.

名称会话在当前上下文中不存在.

谁能帮我.

Am using windows application using c#. How to set session? i typed Session["Time"]=DateTime.Now; .But the error is coming like this.

The name session does not exist in the current context.

Can anyone help me. Am new to this technology.

推荐答案

会话在Winforms应用程序中不存在-仅在基于Web的会话中.

您必须执行的操作取决于要达到的目标:配置设置可在运行之间保留数据,但是在应用程序内,只要不超出范围和/或获取数据,数据将在运行期间保留.处置.
因此,与基于Web的网站不同,表单中的类级别变量将在每次按按钮之间保留下来.

您要达到什么目的?
Sessions do not exist in Winforms applications - only in web based.

What you have to do depends on what you are trying to achieve: Configuration settings preserve data from run to run, but within an application, data is preserved for the duration of the run, provided it does not go out of scope and/or get Disposed.
So class level variables within your form will be preserved from button press to button press, unlike web based.

What are you trying to achieve?


您不能.也没有等效项.因此,您需要使用临时存储(数据库等)来实现自己的逻辑.
You cannot. There are no equivalents either. So you need to implement your own logic using a temporary store (database etc) to do this.


会话对象是基于Web的,因此在这里,由于您的应用程序是桌面应用程序,因此我建议您将您要保持一致性的数据作为静态数据.静态变量在整个活动线程中都可用.
Session object is web based, so here since your application is Desktop application i would suggest you to have the data you want consistency for as static. Static variables are available throughout the alive thread.


这篇关于如何在Windows应用程序中使用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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