Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have written this code on Application_Error function.
C#
SessionsID = HttpContext.Current.Session.SessionID.ToString();

if (Session["USERID"] != null)
               {
                   UserName = Session["USERID"].ToString();
               }

Can any one tell me how this is not support in this context in Application_Error function.
Posted
Updated 26-Dec-11 1:55am
v2
Comments
Anuja Pawar Indore 26-Dec-11 7:55am    
Added pre tag

Hi,

Here are u check string value:

C#
SessionsID = HttpContext.Current.Session.SessionID.ToString();

if (Session["USERID"].ToString() != "")
{
UserName = Session["USERID"].ToString();
}
 
Share this answer
 
 
Share this answer
 
Hi,
I think

First:

C#
SessionsID = HttpContext.Current.Session.SessionID.ToString();
 
if (Session["USERID"].ToString() != string.Empty)
{
    UserName = Session["USERID"].ToString();
}


Second:

C#
SessionsID = HttpContext.Current.Session.SessionID.ToString();
 
if (Session["USERID"] != null)
{
    if(Session["USERID"] != string.Empty)
         UserName = Session["USERID"].ToString();
}
 
Share this answer
 
Comments
Bhanu Pratap Verma 27-Dec-11 0:16am    
Hi Its also not working.
C#
if (Session["USERID"] != null)
 
Share this answer
 
v2
The problem is accessing the session. Because sometimes the session is null.
Notice that this works just fine for HTTP 500 (Server Error) errors, but if it's a HTTP 404 (File Not Found) error, the Session is always null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900