Results 1 to 10 of 10

Thread: Session problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Session problem

    I am facing problem with the session variables.

    I have a login page in my website. Which sets a session variale (Session("username")=form.username) at the time of login.

    In signout page I have this code. Session("username")="".

    In my other page first I check whether a user is logged in or not by checking variable Session variable. Code is:

    Code:
    If Session("username")="" then
    Response.Redirect("login.asp")
    End If
    If user is already logged in s/he will be directed to his selected page.

    My problem is even if the user has signout and if he tries to access protected first time just after signout he sees the page and previous used username is shown as logged in. But if the page is refreshed once, he is directed to login page, means even after signout the session variable still holds last logged in username name, but once the page is refreshed it clears the session variable and direct the user to login page.


    Can any one tell me where is the problem?


    Thanks

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Session problem

    Originally posted by sillylady
    I am facing problem with the session variables.

    I have a login page in my website. Which sets a session variale (Session("username")=form.username) at the time of login.

    In signout page I have this code. Session("username")="".

    In my other page first I check whether a user is logged in or not by checking variable Session variable. Code is:

    Code:
    If Session("username")="" then
    Response.Redirect("login.asp")
    End If
    If user is already logged in s/he will be directed to his selected page.

    My problem is even if the user has signout and if he tries to access protected first time just after signout he sees the page and previous used username is shown as logged in. But if the page is refreshed once, he is directed to login page, means even after signout the session variable still holds last logged in username name, but once the page is refreshed it clears the session variable and direct the user to login page.


    Can any one tell me where is the problem?


    Thanks
    Thats because your browser is loading the Cached copy. Put the following lines in the pages you want to protect. It will instruct the browser no to cache the page.

    I put the code in an Include file ...

    VB Code:
    1. Response.CacheControl="no-cache"
    2. Response.AddHeader "Pragma","no-cache"
    3. Response.Expires=0
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253
    Thanks Danial it's working.



    Thanks

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Shouldn't you be Session.Abandon()ing instead?

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by mendhak
    Shouldn't you be Session.Abandon()ing instead?
    Session.Abandon clears the session, but if you dont instruct the browser not to cache the page, first time the cached page will be loaded even if the user is not authenticated (e.g Session dont exist).

    I use :
    Session("Username")=""
    Session.Abandon

    Edit : Just realised you are refering to his/her Session("Username")=""

    Yes its better to use Session.Abandon, though some time it fails to work, so to be in the safe side its better to clear it manually first and then using Session.Abandon
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Ah well, those days are behind me now, hopefully. You should consider moving to ASP.NET, Danial. Worth the learning, see?

  7. #7
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by mendhak
    Ah well, those days are behind me now, hopefully. You should consider moving to ASP.NET, Danial. Worth the learning, see?
    I have, I dropped ASP a long time ago. Ever since I touched C# i have never looked back . I bet you using VB.net in your ASP.net .

    I like answering ASP questions here, havent become a Expert in ASP.net just yet
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Danial


    I like answering ASP questions here, havent become a Expert in ASP.net just yet
    Same here.

    A bit of advice: Take a look at the questions being posted there, try it out yourself, and if you get a solution, post it. If someone else has a better solution, they do eventually post it, so you can take a look at that as well. Posting in the VB.NET forum has helped me gain a lot more in terms of practicality than books.

  9. #9
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by mendhak
    Same here.

    A bit of advice: Take a look at the questions being posted there, try it out yourself, and if you get a solution, post it. If someone else has a better solution, they do eventually post it, so you can take a look at that as well. Posting in the VB.NET forum has helped me gain a lot more in terms of practicality than books.
    Yep thanks,

    I have started posing/replying in C# & ASP.net forum. I despise vb.net (no disrespect), i just fallen in love with c# .


    Sorry SillyLady for the off-topic post, hope we could persuade you to upagrade to asp.net too, its so much better you cant even start to compare...
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Yes, we need a silly little lady in the VB.NET forums.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width