If you're running IIS 6+, and you have your server setup as a web farm
or your application pool is set up as a web garden (http://
www.dotnetuncle.com/Aspnet/91_web_farm.aspx), and you're using the
default in-process session state, then there is a high possibility
that each request for the web page will go to a different process.
When that happens, each process has it's own session state. Your local
PC probably is only using a single worker process with the application
pool, in which case you wouldn't see the problem.

For example, let's assume you are using a web garden and have your
application pool configured to utilize two worker processes. When you
submit the first page request, it saves the session state into worker
process #1.  Now you submit a button on the page, which posts the page
back to the web server for the second time.  This time it might go
back to worker process #1, or it might go to worker process #2.  If it
goes to process #1, then your session state is intact and you can
retrieve the saved values with no issue.  If on the other hand, it
goes to process #2, then your session state is associated with a
different process, and it doesn't know about the previous session data
that you saved because that was saved under process #1.  This will
make it appear like you had never saved the session data at all.  I
know a lot about this because I had the same issue happening since our
test web server was only using a single worker process with the
associated application pool, while our production server was using 2
worker proceses.  This left me scratching my head for quite a while
until I saw the difference between the application pool
configurations.

If you are not using a web farm, or your application pool is only
using one worker process, then another reason for actually loosing
your session information could occur when an application pool
automatically recycles.  Depending upon your application pool
configuration, it might be set to recycle often.  The default setting
is to recycle the associated worker process every 1740 minutes (29
hours).  If the recycle occurs while someone is using a web
application that references session variables, then the next postback
to the web server would no longer have the session data available
since it is associated with the memory of the previously active worker
process.

Depending upon your situation, you can fix the problem in one of
several ways:
1) If your application pool is configured as a web garden, then you
could fix the issue of missing session data by configuring the
application pool to only use one worker process.  Of course, if this
is a busy web application, then doing this might cause issues with the
response time. This was my resolution since the specific application
happened to be one that only a few people used each day.  I've since
decided not to use session variables, and found other ways to handle
the data between posts.
2) If your using a web garden, then the only real way to resolve the
session issue is to change the configuration of how you store the
session data to either a separate State Server Service, or you can
configure it to store the session data into a MS SQL Server database.
There are pros and cons to each of these.  See the URL referenced
previously for more information.
3) If neither of the aforementioned resolutions is possible for one
reason or another, then you will need to look into changing how your
application stores it's data between posts, and not use session
variables.  Some other options are ViewState, Client-side Cookies,
storage in a database, storage in an XML file, etc.

I hope this information has helped you!

Larry



On Jun 2, 2:54 pm, SUP MUK <[email protected]> wrote:
> i v stored some values into session variables at the time of login(i.e user
> id,user name cetc..)..while running this website in localhost(iis)this works
> fine. but while i upload this in windows webserver it is giving errors like
> *Object Instance not set to an instance of an object etc* when i am trying
> to access the value of session variables ,it seems that session variables
> failed to store the data(after logging in while navigating through the
> website session variables become null).
>
> how can I overcome the problem? please suggest..............I am waiting
> ..............

Reply via email to