Solved 3.5  VB Forms Authentication Login and session variables problem

Posted on 2011-04-26
Last Modified: 2012-05-11

I have an 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
Question by:demerg
    LVL 9

    Expert Comment


    And Clear your sessions on page unload.
    LVL 9

    Expert Comment


    Author Comment

    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?

    LVL 9

    Accepted Solution

    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

    Author Closing Comment

    Many Thanks RadCaesar

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now