473,698 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird... Session[] not working from static classes (IIS only problem)

Hi there,

I'm having a problem with a method which resides on a static class I have on
my ASP.NET application.

public static string FilterCenter(st ring fieldName)
{

string centers =
((User)System.W eb.HttpContext. Current.Session["userdata"]).Centers;

...some more code...
}

The point here is how I cast Session["userdata"] to the (User) type so I can
access the Centers property. This method works fine on my development
machine with the VS 2005 web server.

However, after deploying to the Windows 2003 server, I get this exception:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

That is, it seems that Session["userdata"] is now null. Again, this only
happens on the production IIS server.

So... am I doing something wrong here trying to access Session[] from a
static class? If not, why does it work on VS 2005 but fails on IIS 6?

Thanks in advance,

-Benton

Jan 23 '07 #1
3 1579
"Benton" <co*******@gmai l.comwrote in message
news:51******** *****@mid.indiv idual.net...
I'm having a problem with a method which resides on a static class I have
on my ASP.NET application.
You have to be *really* careful with static classes in ASP.NET:
http://support.microsoft.com/kb/893666
The point here is how I cast Session["userdata"] to the (User) type so I
can access the Centers property. This method works fine on my development
machine with the VS 2005 web server.
Ah yes, but you're the only person connected to it, so the fact that you're
using statics doesn't matter... :-)
Jan 23 '07 #2
either session is disabled on the server or the server is recycling. if
you use inproc sessions, you should always check for null, and have
recovery code.

-- bruce (sqlwork.com)

Benton wrote:
Hi there,

I'm having a problem with a method which resides on a static class I
have on my ASP.NET application.

public static string FilterCenter(st ring fieldName)
{

string centers =
((User)System.W eb.HttpContext. Current.Session["userdata"]).Centers;

...some more code...
}

The point here is how I cast Session["userdata"] to the (User) type so I
can access the Centers property. This method works fine on my
development machine with the VS 2005 web server.

However, after deploying to the Windows 2003 server, I get this exception:

[NullReferenceEx ception: Object reference not set to an instance of an
object.]

That is, it seems that Session["userdata"] is now null. Again, this only
happens on the production IIS server.

So... am I doing something wrong here trying to access Session[] from a
static class? If not, why does it work on VS 2005 but fails on IIS 6?

Thanks in advance,

-Benton
Jan 23 '07 #3
either session is disabled on the server or the server is recycling. if
you use inproc sessions, you should always check for null, and have
recovery code.

-- bruce (sqlwork.com)
Thanks for the advice. I've overcome this using a different approach. Any
clues why it works on VS 2005 intregrated web server but fails on IIS 6?
Same project, same web.config

Cheers,

-Benton

Jan 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2023
by: Scott Wickham | last post by:
I'm having a problem saving session information on one form and retrieving it on a subsequent form...for only one out of a number of users. Actually, I'm not absolutely certain it's a session problem but I'm hoping the experts can help me figure that out. Our application uses a session variable to "pass" info from one form to the next. It has always worked fine for our users until a few weeks ago when one of our users started having a...
6
1907
by: Willem van Rumpt | last post by:
Hi all, I was wondering: Why isn't it possible to write "static classes". By this I mean a class that will _never_ get instantiated, but will always work on and with other static members of its class. The class would in effect behave like a "classic" win32 dll and its exported functions, only this time referred by <classname>.<ExportedFunction> I know (how) I can achieve the same results with a singleton, but why
9
4360
by: Joanna Carter \(TeamB\) | last post by:
Following on from the other discussion, I have to just check something out with reference to disposal of resources held in static fields. I have a Persistence Framework that is 'globally accessible'. In Delphi, I would use a class of static methods to enforce the singleton, and I added static fields to hold things like the database connections, etc. This worked fine in Delphi because we have unit initialisation/finalisation sections...
3
1011
by: Ben | last post by:
Do static classes with static members persist between page hits in asp.net? I'm seeing some very weird behavior and that might explain it. I'm not really sure the best way to test it, so I thought I'd ask :) TIA, Ben
9
20571
by: Chuck Cobb | last post by:
I am creating some static classes with static methods and static variables, but I have a question: What is the lifetime of static classes and static variables? Is there any risk that these items might be garbage collected if they're not used for a period of time? For example: public static class test { static Collection<string> coll;
7
2410
by: Brybot | last post by:
Apparently it is not possible for a static class to extend an abstract class? I was wondering how else I might be able to go about my problem here? I have a base class Parent which has a static method and an abstract method. public abstract class Parent { public static bool True()
4
2365
by: thomson | last post by:
Hi All, Can any one tell me the demerits of using static classes in Web Application,what is the scope of this kind of class Thanks in Advance Thomson
4
1489
by: JC | last post by:
Suppose an ASP.Net project contains a public static class with public methods and members that are used throughout the application. Of course being static, there is only copy of the class within the application. Now suppose two users access the Web site simultaneously. Does each user see his/her own single copy of the static class, or do they share the class, thus creating a problem that can only be solved if one use blocks the other...
4
3304
by: Rene | last post by:
Hi, I was wondering if anyone could tell me why extension methods must be declared on static classes. I mean, why not allowing them to be declared as static methods in regular instance classes? In case you are wondering, I am only curious to find out the reason for this limitation. I don't really have a need to declare extension method on non static classes. I am just curious.
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.