全局会话变量 [英] Global Session Variable

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

问题描述

我有一个App_Code文件夹的网站,其中包含Global.asax.cs和一个名为Upload.cs的

文件。


我想通过Upload.cs在

default.aspx中设置的会话变量(用户名)。


在default.aspx中设置会话变量没问题,但是如何将它提供给Upload.cs?
?我认为这是将b / b
写入以下两个文件的问题:Global.asax.cs和

很明显,Upload.cs,但究竟是怎么回事完成了吗?


我知道这是一个初学者的问题,我已经尝试找到了答案,

但不知何故看起来似乎更难了找到最基本问题的答案。

I have a site with an App_Code folder that has Global.asax.cs and a
file named Upload.cs.

I want to pass Upload.cs a Session variable (username) that is set in
default.aspx.

Setting up a session variable in default.aspx is no problem, but how
do I make it available to Upload.cs? I think it''s a matter of
writting code into the following two files: Global.asax.cs, and
obviously, Upload.cs, but how exactly is it done?

I know this is a beginner question, and I''ve TRIED finding the answer,
but somehow it seems like it''s harder to find answers to the most
basic questions.

推荐答案

" Dave" < on ******** @ gmail.comwrote in message

news:11 ********************* @ q75g2000hsh.googlegro ups.com ...
"Dave" <on********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...

在default.aspx中设置会话变量没问题,但是我怎么用
使它可用于Upload.cs?
Setting up a session variable in default.aspx is no problem, but how
do I make it available to Upload.cs?



你不需要传递Session变量 - 无论如何它们都可用于

整个Session ...


string strVariable = HttpContext.Current.Session [" MyVariable"]。ToString();


-
http://www.markrae.net

You don''t need to pass Session variables around - they are available to the
entire Session anyway...

string strVariable = HttpContext.Current.Session["MyVariable"].ToString();

--
http://www.markrae.net

会话变量可供用户在

单个浏览器会话中访问的所有页面使用。你得到它们的方式和设置它们的方式相同,或任何其他的b $ b变量。


-

HTH,

Kevin Spencer

Microsoft MVP


打印组件,电子邮件组件,

FTP客户端类,增强型数据控件等等。

DSI PrintManager,Miradyne组件库:
http://www.miradyne.net


" Dave" < on ******** @ gmail.comwrote in message

news:11 ********************* @ q75g2000hsh.googlegro ups.com ...
Session variables are available to all pages that are visited by a user in a
single browser session. You get them the same way you set them, or any other
variable.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Dave" <on********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...

>我有一个网站,其App_Code文件夹包含Global.asax.cs和

文件名为Upload.cs。


我想传递Upload.cs一个在

default.aspx中设置的会话变量(用户名)。


在default.aspx中设置一个会话变量没问题,但是如何将它提供给Upload.cs?我认为这是将b / b
写入以下两个文件的问题:Global.asax.cs和

很明显,Upload.cs,但究竟是怎么回事完成了吗?


我知道这是一个初学者的问题,我已经尝试找到了答案,

但不知何故看起来似乎更难了找到最基本问题的答案。
>I have a site with an App_Code folder that has Global.asax.cs and a
file named Upload.cs.

I want to pass Upload.cs a Session variable (username) that is set in
default.aspx.

Setting up a session variable in default.aspx is no problem, but how
do I make it available to Upload.cs? I think it''s a matter of
writting code into the following two files: Global.asax.cs, and
obviously, Upload.cs, but how exactly is it done?

I know this is a beginner question, and I''ve TRIED finding the answer,
but somehow it seems like it''s harder to find answers to the most
basic questions.





一对夫妇基本的东西,添加到其他东西。


当你把东西放入(或取出)时,它的类型为对象。

所以当你输入一个1001的EmpID(int)时....它作为一个对象进入。


当你把它拉出来时,你必须记住它的一个物体,然后

cast / convert它是你想要的正确类型。


IN:


int empid = 1001;

HttpContext.Current .Session [" MyKey"] = empid;

OUT


int foundEmpId = Convert.ToInt32(

HttpContext.Current .Session [" MyKey"]);


或更好


int foundEmpId = 0;

if (null!= HttpContext.Current.Session [" MyKey"])

{

foundEmpId = Convert.ToInt32(

HttpContext.Current .Session [" MyKey"]);

}


你去吧。这应该会有所帮助。


Dave < on ******** @ gmail.comwrote in message

news:11 ********************* @ q75g2000hsh.googlegro ups.com ...

A couple of basic things, to add to the others.

When you put something in (or take it out), it is of type "object".

So when you put in an EmpID (int) of "1001" .... it goes in as an object.

When you pull it out, you have to remember its an object, and then
cast/convert it to the proper type you want.

IN:

int empid = 1001;
HttpContext.Current.Session["MyKey"] = empid;
OUT

int foundEmpId = Convert.ToInt32 (
HttpContext.Current.Session["MyKey"] );

or better

int foundEmpId = 0 ;
if(null != HttpContext.Current.Session["MyKey"] )
{
foundEmpId = Convert.ToInt32 (
HttpContext.Current.Session["MyKey"] );
}

There you go. That should help.

"Dave" <on********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...

我有一个App_Code文件夹的网站,其中包含Global.asax.cs和

名为Upload.cs的文件。


我想传递Upload.cs一个在

default.aspx中设置的会话变量(用户名)。


在default.aspx中设置会话变量没问题,但是如何将它提供给Upload.cs?我认为这是将b / b
写入以下两个文件的问题:Global.asax.cs和

很明显,Upload.cs,但究竟是怎么回事完成了吗?


我知道这是一个初学者的问题,我已经尝试找到了答案,

但不知何故看起来似乎更难了找到最基本问题的答案。
I have a site with an App_Code folder that has Global.asax.cs and a
file named Upload.cs.

I want to pass Upload.cs a Session variable (username) that is set in
default.aspx.

Setting up a session variable in default.aspx is no problem, but how
do I make it available to Upload.cs? I think it''s a matter of
writting code into the following two files: Global.asax.cs, and
obviously, Upload.cs, but how exactly is it done?

I know this is a beginner question, and I''ve TRIED finding the answer,
but somehow it seems like it''s harder to find answers to the most
basic questions.



这篇关于全局会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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