Reputation: 2210
I need to get the current user id of the user and I tried the following code
ClsUser User = (ClsUser)Session["USER"];
but it shows error that it should write in the non static function..so my question is is how to get the current session value in static field
Upvotes: 1
Views: 679
Reputation: 17614
Here is the solution also check for null
values
public static class UserInfo
{
public static ClsUser showName()
{
return (ClsUser)(HttpContext.Current.Session["USER"]);
}
}
Upvotes: 1
Reputation: 13579
If you are using static function you need to use
HttpContext.Current.Session
so you can directly reference the namespace in the static function
try somethin like
ClsUser User = (HttpContext.Current.Session["USER"] as ClsUser);
Upvotes: 3