【发布时间】:2010-09-08 04:19:42
【问题描述】:
大家好,我在实用程序类中有一个函数,它返回当前会话用户 ID。 它抛出未设置为对象实例的对象引用?如何检查它是否为空并删除此错误?
public static string GetSessionUserID
{
get
{
string userID = "";
if (System.Web.HttpContext.Current.Session["userID"].ToString() != null)
{
userID = System.Web.HttpContext.Current.Session["userID"].ToString();
}
if (userID == null)
{
throw new ApplicationException("UserID is null");
}
else
return userID;
}
}
【问题讨论】: