.cs文件中的HttpContext.Current.Session == null [英] HttpContext.Current.Session==null in .cs file

查看:86
本文介绍了.cs文件中的HttpContext.Current.Session == null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我创建了ASP.NET项目,其中我有一个文件Admin.cs。它包含

静态类Admin以及一些方法和属性。问题是在

属性中获取引用HttpContext.Current.Session为null,尽管对于

实例HttpContext.Current.Application或HttpContext.Current.Request是

不为空:

公共静态类管理员


{


...


设定


{


HttpContext.Current.Session [" Database"] = value ; //这里好的


}


get


{

object db = HttpContext.Current.Session [" Database"]; //这里有问题


if(db == null)


返回null;


返回db.ToString();


}


...


}


有谁可以解释我为什么?如何在我的代码中使用Session对象?

/ RAM /

Hello,
I have created ASP.NET project in which I have a file Admin.cs. It contains
static class Admin with some methods and properties. The problem is that in
property get a reference HttpContext.Current.Session is null, although for
instance HttpContext.Current.Application or HttpContext.Current.Request is
not null:
public static class Admin

{

...

set

{

HttpContext.Current.Session["Database"] = value; // HERE OK

}

get

{

object db = HttpContext.Current.Session["Database"]; // HERE PROBLEM

if (db == null)

return null;

return db.ToString();

}

...

}

Could anyone explain me why? How to use Session object in my code?
/RAM/

推荐答案

R.A.M。写道:
R.A.M. wrote:

您好,

我创建了ASP.NET项目,其中我有一个文件Admin.cs。它包含

静态类Admin以及一些方法和属性。问题是在

属性中获取引用HttpContext.Current.Session为null,尽管对于

实例HttpContext.Current.Application或HttpContext.Current.Request是

不为空:

公共静态类管理员


{


...


设定


{


HttpContext.Current.Session [" Database"] = value ; //这里好的


}


get


{

object db = HttpContext.Current.Session [" Database"]; //这里有问题


if(db == null)


返回null;


返回db.ToString();


}


...


}


有谁可以解释我为什么?如何在我的代码中使用Session对象?

/ RAM /

Hello,
I have created ASP.NET project in which I have a file Admin.cs. It contains
static class Admin with some methods and properties. The problem is that in
property get a reference HttpContext.Current.Session is null, although for
instance HttpContext.Current.Application or HttpContext.Current.Request is
not null:
public static class Admin

{

...

set

{

HttpContext.Current.Session["Database"] = value; // HERE OK

}

get

{

object db = HttpContext.Current.Session["Database"]; // HERE PROBLEM

if (db == null)

return null;

return db.ToString();

}

...

}

Could anyone explain me why? How to use Session object in my code?
/RAM/



您是否已调试代码并验证了它'实际上是Session对象的引用

为空,而不仅仅是项目

集合不包含密钥数据库?


-

G?跑Andersson

_____
http://www.guffa.com


Uzytkownik" G?ran Andersson" < gu *** @ guffa.comnapisal w wiadomosci

news:un ************** @ TK2MSFTNGP05.phx.gbl ...
Uzytkownik "G?ran Andersson" <gu***@guffa.comnapisal w wiadomosci
news:un**************@TK2MSFTNGP05.phx.gbl...

您是否已调试代码并验证它实际上是对象为空的参考

,而不仅仅是项

集合不包含密钥数据库?
Have you debugged the code and verified that it''s actually the reference
to the Session object that is null, and not simply that the Items
collection doesn''t contain the key "Database"?



是的,我调试了代码。 HttpContext.Current.Application,

HttpContext.Current.Cache,HttpContext.Current.Response,

HttpContext.Current.Request不为null,它们引用有效对象。只有

HttpContext.Current.Session为空。

它对我来说很奇怪,所以我发了帖子。

你能帮我吗?

/ RAM /

Yes, I debugged the code. HttpContext.Current.Application,
HttpContext.Current.Cache, HttpContext.Current.Response,
HttpContext.Current.Request are not null, they reference valid object. Only
HttpContext.Current.Session is null.
It looks strange for me, so I have sent the post.
Could you help me?
/RAM/


我忘记添加:我将Web服务器从IIS 5.1更改为Cassini 2.

一般来说Cassini工作正常,但也许这就是为什么Session没有工作的原因......我不能使用IIS,因为我在IIS中有内部错误而我没能

解决问题。

/ RAM /
I have forgotten to add: I changed web server from IIS 5.1 to Cassini 2.
Generally Cassini works fine, but maybe that''s the reson why Session doesn''t
work... I cannot use IIS because I had interal error in IIS and I failed to
solve the problem.
/RAM/


这篇关于.cs文件中的HttpContext.Current.Session == null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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