As long as you have System.Web referenced in your using statements, then you should be able to use this:
if (Session != null) {Session.Clear();}
Or
if (Session != null) {Session.Abandon();}
Im not sure why you would you return a string which holds an integer though. A boolean value would make more sense, but you really shouldn't need anything in this context.
Also, your exception handler is attempting to catch a sqlexception, which could also be a source of an object reference error, as you don't appear to have any SQL objects in this function.
I'd probably do this following:
protected bool MemberLogOut()
{
try {
if (Session != null) {Session.Abandon();}
//do any logging and additional cleanup here
return true;
} catch {
return false;
}
}
Edit: if you are in fact calling from outside of your web project, you can just pass the current httpcontext to the following method:
protected bool MemberLogOut(HttpContext context)
{
try {
if (context != null && context.Session != null) {
context.Session.Abandon();
}
//do any logging and additional cleanup here
return true;
} catch (Exception ex) {
//log here if necessary
return false;
}
}