?
Solved

ASP.net Session variable lose their value

Posted on 2006-03-27
11
Medium Priority
?
357 Views
Last Modified: 2008-01-09
Hi,

This is the background of my app:

I have built an ASP.NET-C# application. I have enabled Forms Authentication by authenticating user id and password stored in my SQL Server database.
The Session is configured as InProc in the webconfig file.

The are unsecure and secure pages in the website. Unsecure pages can be accessed by anyone browsing the site  and Secured pages can be accessed only by a registered user after login.

I have used objects stored in Session that are used for parameter sharing  between different web pages(For both Secure and Unsecure pages).

When the user is logged in, the Session variable retain values . The session parameters are passed correctly to different pages and everything works fine.

But when the user logs out, the app does retain the values of the Session. I tried to debug the code and noticed that for each page, the Session_OnStart is fired.

Is this how this is supposed to work. Or let me know what I am missing?

Thanks,
Madhu








0
Comment
Question by:valuesolutions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 3

Assisted Solution

by:spdude
spdude earned 200 total points
ID: 16303074
hi madhu

try using session.abandon() on logout
and
please share global.asax file also
0
 
LVL 23

Assisted Solution

by:naveenkohli
naveenkohli earned 200 total points
ID: 16303244
Do you have a "Logout" button that user used to logout or you mean when user closes browser window?

If its about logging out user by clicking on "Logout" button then you definitely should abandon session by calling "abandon" method as spdude pointed out.
0
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 200 total points
ID: 16305772
You do NOT want to use Session.Abandon() on the logout portion. This will cause ALL current session variables to be erased and recreated from the global.asax. What should be done is just set the variable checked by the session check to be "".
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:ptleitch
ID: 16307863
has your question been resolved? because there are a couple of good suggestions here and i would like to hear about your experience
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 400 total points
ID: 16309280
>>But when the user logs out, the app does retain the values of the Session. I tried to debug the code and noticed that for each page, the Session_OnStart is fired.

r u using relative paths when transfering request from page to page? if not, then session_onstart will be fired everytime a page is requested .. but then the question is how is it workign when the user is logged in .. so the question is what do u mean by logged in? do u have a session variable to check if user is looged in?

Rejo
0
 

Author Comment

by:valuesolutions
ID: 16310512
Hi All,

Let me clarify something first.
I DONT want to loose my Session variables. When the user is logged into mysite(used ASP.NET Forms Authentication for this), the session variables are retained.
But when user just browses the unsecure pages in the site , the session variables are not retained.I am guessing this is because the Session is re-created evrytime the page is refreshed. How do I stop this?

Thanks
Madhu
0
 

Author Comment

by:valuesolutions
ID: 16310581
Hi Rejo,

I am not using relative paths.  I am displaying data in a DataGrid. I want to sort the data based on the Column clicked in the header row. The sort order should toggle between ascending and descending .

I have stored the field clicked and the sortorder stored in Session variables in the datagrid SOrtCommand event. But these fields are always emty when the page is refreshed.

I tried to change the path to relative in my menu item URL. but I still see the problem.Any idea?

Let me know if you need any other details.


Regards,
Madhu


0
 
LVL 28

Expert Comment

by:strickdd
ID: 16310847
It could be in how you are forcing the https:// connection. If you are redirecting to a different application, you will have problems with sessions variables transferring over. Can you give the code that makes the connection secure and the code that logs the user off?
0
 

Author Comment

by:valuesolutions
ID: 16316447
Hi,
I dont use https. All the pages are within the same asp.net C# application

Thanks,
Madhu
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 16318014
>>I am not using relative paths
If u r not, then use it to retain session variables ..

>>I dont use https
then what do mean by secure and unsecure?
0
 

Author Comment

by:valuesolutions
ID: 16324060
Sorry for the misnomer on Secure and UnSecure pages.

Some pages in my app can be accessed by logged in users with certain roles only and some pages are availble to everyone. I have used forms authentication to login site users.

I have used session variables in the aspx page avaiable for all users. But the session variables are retained only when the user has logged in.
-----------------------------------------------------
>>I am not using relative paths
If u r not, then use it to retain session variables ..
----------------------------------------------------------------
I have changed the skmMenu URL to relative path. But still the session  variables are not retained. Should I update anything else?

Thanks,
Madhu

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question