在ASP.NET中使用Session对象 [英] Usage of Session object in ASP.NET

查看:72
本文介绍了在ASP.NET中使用Session对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚被赋予了一项新任务来引导别人创建的网站。但是我绝对是网络新手。该网站位于ASP.NET,C#中。除了Session对象,代码本身并不难理解。我不知道在何处,如何使用以及为什么使用它。请问有人用一个可能的例子来说明Session对象的用法吗?

I've just been given a new task to bootstrap a website created by someone else. But I'm absolutely new to Web. The website is in ASP.NET,C#. The code itself is not hard to understand except for the Session object. I don't understand where, how and why it's used.Could please someone explain the usage of Session object with a possible example?

P.S。这两行是什么意思?

P.S. What would these two lines mean?

    lblPensValue.Text = sh.pensDec((string)Session["connSTR"], 113, 23);
and
    if ((string)Session["connSTR"] == null)


推荐答案

会话用于在网站上存储用户会话的数据。 (此数据存储区是每个用户浏览器会话,并且随时可能被各种应用程序事件擦除)。

Session is used to store data for the user's session on the web site. (this data store is per-user-browser session, and is subject to being wiped at any time by various application events)

通常用于跨多个存储信息

It is generally used to store information across multiple page views in a user's session (ie. visit) to your website.

它可以在用户会话上下文中运行的代码中的任何位置使用;意思是在页面中,还是在会话上下文中运行的适当应用程序生命周期事件中(例如会话开始)

It can be used anywhere in code that runs in the context of the user's session; meaning inside a page, or in the appropriate application lifecycle events which run in the context of a session (such as Session Start)

对于您的示例;

第一个,我无法完全解释,因为我不知道函数 sh.pensDec()应该是什么

The first one, I can't fully explain, as I do not know what the function sh.pensDec() is supposed to do.

第二个是在运行随后的代码之前,检查确保该会话变量中存储了一个值。

The second one is checking to make sure there is a value stored in that session variable, before running the code that follows.

这篇关于在ASP.NET中使用Session对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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