473,738 Members | 11,146 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 1583
"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
2028
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
1910
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
4363
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
1016
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
20579
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
2414
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
2371
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
1491
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
3305
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
8969
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
9335
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...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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
8210
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...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.