Is there a way to check that a Session variable exists without using try/catch?
-
Is there a nice easy way to check Session["x"] exists without trying and catching it? Thanks.
-
Is there a nice easy way to check Session["x"] exists without trying and catching it? Thanks.
-
no need to use try catch for that they are there for different purpose. You can check the session like this:
if(Session["x"]!=null) { //do your work. }
Best Regards, Apurva Kaushal
Oh my I feel like an idoit! I could have sword i tried that and it gave me an error for referencing a somthing that didn't exist but that error was caused by another bug :doh: Thanks for pointing it out for me :)
-
Oh my I feel like an idoit! I could have sword i tried that and it gave me an error for referencing a somthing that didn't exist but that error was caused by another bug :doh: Thanks for pointing it out for me :)
-
Imagine the key has not been added on the session at all, that time do we need to user only try...catch block or is there any other way will work? Ram
-
Imagine the key has not been added on the session at all, that time do we need to user only try...catch block or is there any other way will work? Ram
-
No in that case also you can check the session like that(what I mention). :)
Best Regards, Apurva Kaushal
I tried, it is throwing object ref not set an instance of an object exception. Are you sure :) Ram
-
I tried, it is throwing object ref not set an instance of an object exception. Are you sure :) Ram
That is what you need to check. If you will use the session variable without assigning it then it will thow the exception exactly what you got. So prior to use that you have to check whether that is available or not like this:
if(Session["x"]!=null) { //do your work. }
here x is the variable name you change it with yours one. :)Best Regards, Apurva Kaushal