Reputation: 44352
I have the following test:
if(Session["mykey"] != string.Empty)
{...}
In VS.NET 2010's watch window, the value of Session["mykey"] is "". Yet I still go into the conditional. Do I need some other test?
--- EDIT --- After the above runs, I do reset the object by assigning string.Empty.
Upvotes: 0
Views: 121
Reputation: 32511
try this
if(!string.InNullOrEmpty(Session["mykey"].ToString()))
{
// some code
}
Upvotes: 4
Reputation: 1216
Of course, because you are comparing with the object
of the Sessions
not its text
.
Do like so:
if(Session["mykey"].ToString() != string.Empty)
{...}
other way to go is:
if(Session["mykey"] != null)
{...}
Upvotes: 4