Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

Asp.net 3.5 VB Forms Authentication Login and session variables problem


I have an asp.net 3.5 Visual Basic forms authentication application where I use a login form to query a SQL Server 2005 Database.

If the login parameters are accepted, I create several session variables in the login code behind after querying the database…

Session("UserID") = (customReader("IDNum"))
Session("UserFName") = (customReader("FName"))
Session("UserLName") = (customReader("LName"))
Session("UserEmail") = (customReader("Email"))

And then proceed to open the session on the default page …

FormsAuthentication.RedirectFromLoginPage(Session("UserID"), True)

The bizzar occurance is that on no set time or action from any user, all of a sudden the Default Page which has 2 gridviews that rely on the Session("UserID") to populate themselves return 0 records, even though they just had records in them. What is really odd is the login authentication is still active and the login control on the default page is still showing the Session("UserID").

When the user loggs out and then back again things are back to normal but the same scenario can reoccur at any time.

The web.config is set the forms authentication mode and I have the timeout set to several hours.

Am I doing something wrong loading the session variables?
Why does the site function perfectly and then all of a sudden, the records in the Gridviews disappear and the authentication is still good?

I hope someone can help with this as this is really causing some problems
  • 3
  • 2
1 Solution

And Clear your sessions on page unload.
demergAuthor Commented:
Hi RadCaesar

Not sure if I understand what you are suggesting.

My problem is that the application is losing the session variables without any reason. I don't what to logout, I am having problems where the session variables are being lost after the user logs on.

How is clearing them and signing out going to help with this problem?

sry i thought it was redirected automatically.

ok, Why u set pers cookie as true. try Disable it like below.

FormsAuthentication.RedirectFromLoginPage(Session("UserID"), False)

else try remove Response.Redirect("default.aspx") and use "FormsAuthentication.DefaultUrl" property
demergAuthor Commented:
Many Thanks RadCaesar

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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now