将字符串存储在会话变量中,其中模式为 StateServer

发布于 2024-07-14 14:54:16 字数 556 浏览 5 评论 0原文

如果我在会话变量中存储字符串值,是否需要序列化或反序列化它? 我读到,当您在 web.config 中使用时,

<sessionState mode="StateServer" 
              stateConnectionString="tcpip=127.0.0.1:42424"
              stateNetworkTimeOut="60"
/>

您需要先进行序列化,然后才能将值存储在会话变量中,然后在检索该值时进行反序列化。 我想知道,例如,您是否只需将字符串值放入会话中,例如:

Session("MyStringVar") = "MyStringValue"

当您检索它时,您可以这样做:

DIm strVal as String
strVal = Ctype(Session("MyStringVar"), String)

另外,指定的超时是 60,是以分钟还是小时为单位?

谢谢。

If I store a string value in my session variable, do I need to serialize or deserialize it? I read that when you use in your web.config

<sessionState mode="StateServer" 
              stateConnectionString="tcpip=127.0.0.1:42424"
              stateNetworkTimeOut="60"
/>

You need to serialize before you can store the value in session variable and you would then deserialize when you retrieve the value. I wonder if for example, you just place the string value to a session like:

Session("MyStringVar") = "MyStringValue"

and when you retrieve it, you could just do:

DIm strVal as String
strVal = Ctype(Session("MyStringVar"), String)

Also, is the timeout specified for that is 60, is it in minutes or hours?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-07-21 14:54:16

不会。.net 运行时会处理所有这些事情。

但是,如果您要存储未标记为可序列化的对象,则需要执行自己的序列化。 另外,超时值以分钟为单位。

No. the .net runtime will take care of all of that.

However, you would need to do your own serialization if you were storing an object that wasn't marked as serializable. Also, The timeout value is in minutes.

救赎№ 2024-07-21 14:54:16

对于 web.config 您应该能够执行以下操作:

String myValue = ConfigurationManager.AppSettings["MyValue"].ToString();

对于 Session 和字符串值,您可以执行以下操作,如果它不是字符串,请将字符串替换为对象类型...:

String myValue = (string)Session["MyValue"];

For the web.config you should be able to do:

String myValue = ConfigurationManager.AppSettings["MyValue"].ToString();

For the Session and a string value you can do, if its not a string, replace string with object type...:

String myValue = (string)Session["MyValue"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文