Repost: New Session Created on Post Back!

P

Paul

Tried to post this hours ago, but it still isn't visible. If it's a repeat,
sorry for the inconvenience.

Hello, all ---

Environment: Visual Studio.NET 2003 (C#); Windows 2003 Server; IIS 6.0

Here is the problem I am having. I have created a web custom control in C#
which includes a datagrid, label, and code to support populating and paging
the datagrid. The dataset which contains the data displayed in the datagrid
is stored in a session variable.

The control displays a list of people. This control is used in two pages in
an application. In one instance, it displays the results of a search by
the user in a directory. In the other case, it displays the list of people
working in a department on a page with information about the department.

In all cases where the control is used, a class with search criteria is
passed to a web service which queries a SQL Server 2000 database and returns
a dataset containing records which match the criteria. The dataset is then
stored in a session variable.

When returning the results of a user-defined search, it works perfectly.
When displaying on the page containing information about a department,
paging produces a significant problem. When the user clicks Next, the
datagrid does not display and other data on the page which is based on other
session variables is wrong. I ran the debugger and discovered that every
time the Next is clicked in the control from the department page, the
Session_Start event is fired. When the same control is used in the search
results page, the Session_Start event does not fire when the user clicks
Next, and the paging is flawless.

I have seen two basic solutions in different groups. One says that
something must be in a session variable or the session_start event must be
coded to keep a new session from being created. Session_Start is coded, and
data is placed in session variables before this problem arises, so neither
of these is the problem. The other thing I have seen discussed is a restart
of the ASP process. None of the conditions which should lead to such a
restart seem to apply here.

If any additional information is needed, please let me know. I am at a loss
to even be sure what additional information would be useful at this point.
Any help would be appreciated. Thank you.
 
S

Steven Cheng[MSFT]

Hi Paul,

From your description, you've defined a custom control which will retrieve
some certain data from database and display to end user. Since the data may
contains many records(need paging ), you store them in Session Variables
for later use. However, you found when the user click the "next" button on
page to view the sequential data, the session will be timeout (a new
session started) and the session data lost, yes?

Based on my experience, there are some certain things which may cause the
Session be timeout(restart) in addition to the application(or asp.net
worker process) restart:
1. When there occurs unhandled exception in the web application, if we
haven't manually catch it , the current Session will ended and a new one
started.

2. When we use javascript function showModalDialog to show a ModalDialog
and open another page in this ModalDialog, this will cause the SessionId be
incorrect. Here is a former thread discussin on this problem:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=j9OZbbLZEHA.3120%
40cpmsftngxa06.phx.gbl&rnum=13&prev=/groups%3Fq%3Dsession%2B%2Bsteven%2Bchen
g%26hl%3Den%26lr%3D%26ie%3DUTF-8%26start%3D10%26sa%3DN

In addition, since you mentioned that it work well in one page and not work
in another, have you find any difference between the two page? It'll be
helpful it you can generate a simple page which can repro the hehavior so
that we can do some tests on our side. Thanks


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
P

Paul Smith

Thank you, Steven. Your reply put us on the right track and led us to a bug
in our code in a custom control used as a page header. We had not looked at
this before, since it was a common element for all pages whether they
exhibited the problem or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top