Unexpected session resets

Application resets user session on every single click

Page 1 of 1

3 Replies - 4490 Views - Last Post: 29 August 2007 - 12:15 AM Rate Topic: -----

#1 dotnetasp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-August 07

Unexpected session resets

Post icon  Posted 27 August 2007 - 01:13 AM

I seem to be having a problem passing session variables from one page of my asp.net application to the next. After a few tests I have discovered that for some unexplained reason, every time a button or linkbutton is pressed, the application first resets the session and then executes whatever it is supposed to. For instance, during the initial login page, I run a validation and if the result is positive the username is stored in a new session variable and the next page is loaded using the response.redirect method. However when I try to read the username from the next page the session variable does not even exist - as if the session has been reset and all previous values lost. Unfortunately I don't have the code with me to post, but I was hoping someone might have an idea. If it is of any help, I program with Delphi 2005 for asp.net
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Unexpected session resets

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Unexpected session resets

Posted 27 August 2007 - 08:43 AM

I cant even start troubleshooting this with you until I see the code you're using, sorry.
Was This Post Helpful? 0
  • +
  • -

#3 dotnetasp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-August 07

Re: Unexpected session resets

Posted 28 August 2007 - 05:18 AM

View PostPsychoCoder, on 27 Aug, 2007 - 08:43 AM, said:

I cant even start troubleshooting this with you until I see the code you're using, sorry.


Yeah, I know and I apologise, I am writing these posts from a remote computer that's why most of the times I do so, I forget to take with me a copy of the code (which I develop on a local machine with no internet access). Since most of my programming is done in Delphi, can you at least give me some pointers as to what would be more usefull for you to see, the asp code or the delphi one? I promise to post code too until tomorrow!

However I want to point out that I have run the very same application on my older PC and worked just fine, which has made me believe that it is probably not the code itself but something to do with how asp.net is set to work, maybe a configuration on IIS or whatever. Anyway i WILL post the code soon, apologies for not having done so yet but I DO need your help.
Many thanks
Was This Post Helpful? 0
  • +
  • -

#4 dotnetasp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-August 07

Re: Unexpected session resets

Posted 29 August 2007 - 12:15 AM

OK here's the code, hope it's not too late to get a response. The idea is quite simple, the user logs on to the application from a page called login.aspx. If the login is successfull the user is redirected to main.aspx, while the username is added to a session variable.
Below is part the "codebehind" file that does that when a "Login" button is pressed...

<code>
if dr.GetString(0)=password then //===i.e. if the password is correct
begin
Session.Add('USER_NAME',username);
page.Response.Redirect('~/main.aspx?language='+lang);
end;
</code>

On loading main.aspx I try to retrieve the username from the session variable so the application knows who the user is. The following line of code is the very first line in the Page_Load procedure of the "codebehind" file in main.aspx...

<code>
user := Session['USER_NAME'].ToString;
</code>

At that point I get an error saying that you cannot make a reference to an object that does not exist - as if the session variable was never created. Just for test purposes, I have moved the Session.Add line to various places in the code and discovered that the session variable IS initially created, however when the login button (or any other control) is triggered the application terminates the session and starts a new one BEFORE executing whatever event is associated with that cotrol. That of course erases the variable and consequently there is nothing to read when the main.aspx file is loaded.

So the question really is why is the session ended and restarted everytime a control is triggered? I include the beginnings of the aspx files in case it helps...

login.aspx
<code>
<%@ Page Language="c#" Debug="true" Codebehind="login.pas" AutoEventWireup="false" Inherits="login.TWebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title></title>
</head>
<body style="WIDTH: 1162px; HEIGHT: 504px" bgcolor="#84c225"
ms_positioning="GridLayout">
<form method="post" runat="server">
</code>

main.aspx
<code>
<%@ Page Language="c#" Debug="true" Codebehind="main.pas" AutoEventWireup="false" Inherits="main.TWebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title></title>
</head>
<body ms_positioning="GridLayout">
<form runat="server">
</code>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1