ASP.net Session variable lose their value

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








valuesolutionsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

spdudeCommented:
hi madhu

try using session.abandon() on logout
and
please share global.asax file also
0
naveenkohliCommented:
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
strickddCommented:
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ptleitchCommented:
has your question been resolved? because there are a couple of good suggestions here and i would like to hear about your experience
0
RejojohnyCommented:
>>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
valuesolutionsAuthor Commented:
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
valuesolutionsAuthor Commented:
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
strickddCommented:
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
valuesolutionsAuthor Commented:
Hi,
I dont use https. All the pages are within the same asp.net C# application

Thanks,
Madhu
0
RejojohnyCommented:
>>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
valuesolutionsAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.