i have a aspx page and custom httphandler in same domain. In the aspx page (test.aspx), i use
<%@ Page Language="C#" %>
<%
HttpContext.Current.Session["UserID"] = "ABC";
%>
to create a session variable, but when i want to call the variable in httphandler
public class JpgHttpHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
response.Write(HttpContext.Current.Session["UserID"].ToString());
}
}
there is a error message when i toggle the httphandler:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
how can i call the session from httphandler?
thanks
Update
changed the code to
if (context.Session["UserID"] != null)
response.Write(context.Session["UserID"].ToString());
it is strange, when i use ip to access the webpage, it works. But i use the domain name access the page, it displays blank