Current location: Hot Scripts Forums » Programming Languages » ASP.NET » urgent: session timeout occurs unexpectedly in ASP.net


urgent: session timeout occurs unexpectedly in ASP.net

Reply
  #1 (permalink)  
Old 10-10-05, 01:49 PM
seemagaur seemagaur is offline
New Member
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question urgent: session timeout occurs unexpectedly in ASP.net

I am doing a website with asp.net. i have used session variable in my GLOBAL.ASAX file. the code is given below:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session.Timeout = 100
Session("Loggedin") = "No"
End Sub

Sub Session_End(Sender As Object, E As EventArgs)
' Code that runs when a session ends

Session.Abandon()
Response.Redirect("index.aspx")
End Sub
----------------------------------------------------------
And in WEB.CONFIG i have used the following information inside <system.web> tag :

<sessionState mode="InProc"
cookieless="false"
timeout="100"/>

<pages buffer="false"
enableSessionState="true"
smartNavigation="false"
autoEventWireup="true"
validateRequest="false"
enableViewStateMac = "false"
enableViewState="true"/>
----------------------------------
I am storing the user details in sql database.
In the login page when theuser enter the usernam and pwd i check with the backend for valid username and pwd. Then i assign

session variable values if valid else i dont let it.
And then in every page i check if session variable is valid if not i do a server.transfer("index.aspx") to the login page.

Here, index.aspx is my login page.
This below code is included in every page after a succesful login to check for valid user. other than that 8i have not put

anyother check to find out valid user.
----------
Sub Page_Load(Sender As Object, E As EventArgs)
if Session("Loggedin") = "No" then
server.transfer("index.aspx")
end if
end sub
----------

Even after using these things when i login suddenly after a minute i am logged out though i am adding/deleting/viewing

records at the moment.
Please please tell me where i am going wrong. I have to give this project to my boss soon and i am stuck here since i am not

able find out the problem why the session expires and i am logged out and send back to the login page.
Seema

(Mail ID: gaur.seema at rediffmail.com)
Reply With Quote
  #2 (permalink)  
Old 10-11-05, 08:09 AM
rrhodes's Avatar
rrhodes rrhodes is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Hi seemagaur,

I can't see any immediate problems with your code, but my techniques for doing the same are different:

1) Don't mess with Session_Start and Session_End events (you've already got the redirect in your page check, and your code in Session_End seems redundant compared to the rest).

2) In your login script, set your Session("Loggedin") = "Yes" after successful login.

3) In your page test for being logged in, make your test check for whether they have logged in (not that they haven't logged in). That is, if they have not logged in, no session var will be set and you can first check the var to not be "IsEmpty()" and then check for a value of "Yes". Comparing an empty session var against "Loggedin" = "No" will probably not evaluate if the session var is empty.

As for the timing out after a minute - I'm not sure. Keep in mind the following factors could restart your application if in a shared development enviroment and drop your session: 1) Saving new web.config or machine.config, 2) rebuilding the application, 3) restartig IIS

Maybe some of that will help.
__________________
Robert
Gee! Web Tools
Web Content Management / Internet Marketing modules including:
Page Editor - Calendar Manager - News Editor - Contact Organizer - Mail Wizard
Reply With Quote
  #3 (permalink)  
Old 10-11-05, 05:05 PM
seemagaur seemagaur is offline
New Member
 
Join Date: Oct 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thanks robert

I tried it and it seems that it is working..i will make someone else also cross check coz i cant believe it that it is working.have been struggling with this problem even after finishing my work on time. There is one other problem though. When i login and click any hyperlink then the address bar shows the page link of the page i am navigating to which is correct but even when i come back to the index page it still shows the old page link in the Address bar. Any idea why? and how i can correct it?

Once again thanks for your help
Seema
Reply With Quote
  #4 (permalink)  
Old 10-11-05, 11:10 PM
rrhodes's Avatar
rrhodes rrhodes is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
I believe Server.Transfer tends not to change the URL, and Response.Redirect will change it. There are pros and cons of each method (but I forget what they are, you might searh on them).
__________________
Robert
Gee! Web Tools
Web Content Management / Internet Marketing modules including:
Page Editor - Calendar Manager - News Editor - Contact Organizer - Mail Wizard
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help for using session variable in asp.net rajan ASP.NET 0 07-27-05 01:39 AM
Session timeout ... help plz harpinder PHP 1 04-30-05 06:42 AM
Session timeout, need an example, book not show one Spreegem PHP 4 10-16-04 10:10 PM
session timeout, loosing data entry MaritimeSource PHP 1 05-29-04 01:32 AM
Urgent need of ASP.NET Programmer(s) superprogrammer Job Offers & Assistance 1 02-15-04 05:24 PM


All times are GMT -5. The time now is 01:07 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.