use*_*909 0 c# asp.net session-variables
In the below code I have Session variable in which I want to check whether it is null or not. Please help me to do this.
(SearchDoc) is class.
var SearchDoc = (SearchDoc)Session["Documentname"];
var oDocumentID = SearchDoc.ClientID;
var Documentid = SearchDoc.DocumentID;
if (SearchDoc == null)
{
}
Run Code Online (Sandbox Code Playgroud)
This is the safest approach :
if ((HttpContext.Current.Session !=null && Session["Documentname"] as SearchDoc!= null))
{
//do what you want with
((SearchDoc)Session["Documentname"])
}
Run Code Online (Sandbox Code Playgroud)
2 things to notice :
| 归档时间: |
|
| 查看次数: |
4040 次 |
| 最近记录: |