dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: Urgent plz.

  1. #1
    Join Date
    Apr 2004
    Posts
    71

    Urgent plz.

    urgent plz.

    I want to ask you friends how to use session by VB in the asp.net pages

    actually I used by C# like

    String valid = (String) Session["admin"];
    if(valid!=null){
    Response.Redirect("admin.aspx");

    but may we do it by VB

    I'm waitning your relpy

    thanks

  2. #2
    Join Date
    Jul 2004
    Posts
    300
    I believe implicit typecast is fine in VB so you could do
    if (Session("admin") is not Nothing)
    'code here

    But I use C# so I'm not too familiar with VB syntax.

  3. #3
    Join Date
    Apr 2004
    Posts
    71
    thanks

    but it doesn't work

  4. #4
    Join Date
    Dec 2004
    Location
    Saint Petersburg, Florida
    Posts
    32
    Session in VB.Net:

    if Session.Item("Admin") is nothing then
    ' put whatever code you need here
    end if


    if Session("Admin") is nothing then
    ' put whatever code you need here
    end if

    should work too.

    If you want to cast the session variable later, you can use:

    CType(Session.Item("Admin"), String) to cast it to a string, or whatever it might be.

    Good Luck!

    Happy New Year!

  5. #5
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    You can just treat a session variable as a string and use the len function. If
    If len(session("userid")) = 0 then

  6. #6
    Join Date
    Apr 2004
    Posts
    71
    thanks

    it works now

    but how can i use the session timeout and what are its benifits

  7. #7
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    sessions expire after 20 minutes (not really but they are supposed to be default). The trouble is the asp.net session is not reliable, infact session end events do not even fire right as a session ends, they fire after the session but not immediatly. I would actually suggest against using the session for anything where you need the time to be precise. I would use a cookie. Plus you can really make a cookie last for as long as you want, its a good way to store a login.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles