[英]Object reference not set to an instance of an object
I am getting below error when i am trying do sorting. 我在尝试排序时遇到错误。 Object reference not set to an instance of an object.
你调用的对象是空的。
public static string SortColumn
{
get
{
return HttpContext.Current.Session["SORT_COLUMN"].ToString();
}
set
{
HttpContext.Current.Session["SORT_COLUMN"] = value;
}
}
please help me on this... 请帮帮我...
Session["SORT_COLUMN"]
can return null
and you can't call something on nothing , so ToString
would fail. Session["SORT_COLUMN"]
可以返回null
,你不能呼吁什么 东西 ,所以ToString
会失败。
Also, HttpContext.Current
could return null
, meaning you can't access Session
- this can happen if you're trying to access the context from the global.asax code. 此外,
HttpContext.Current
可能返回null
,这意味着您无法访问Session
- 如果您尝试从global.asax代码访问上下文,则会发生这种情况。
You have to initialize the Session variable before you access the getter. 在访问getter之前,必须初始化Session变量。 Otherwise you have to check:
否则你必须检查:
return HttpContext.Current.Session["SORT_COLUMN"] != null ?
HttpContext.Current.Session["SORT_COLUMN"].ToString() : string.Empty
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.