Click to See Complete Forum and Search --> : Urgent plz.
al_3asel
12-30-2004, 10:20 AM
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
mattyblah
12-30-2004, 11:18 AM
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.
al_3asel
12-30-2004, 11:49 AM
thanks
but it doesn't work
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!
PeOfEo
12-30-2004, 03:11 PM
You can just treat a session variable as a string and use the len function. If
If len(session("userid")) = 0 then
al_3asel
12-30-2004, 04:06 PM
thanks
it works now
but how can i use the session timeout and what are its benifits
PeOfEo
12-30-2004, 11:02 PM
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.