Recently, in a project, Ajax was used to call the ashx file. In the ashx file, session is useful, but the session cannot be obtained. After debugging, the cause of the error is as follows:
Roughly as follows:
Session ["loginname"] is empty and cannot be tostring ();
Context. session ["ID"]
"Context. Session" causes an exception of the "system. nullreferenceexception" type.
Base {system. systemexception}: {"the pointer to this method is null. "}
Check msdn to get the ashx file. To use the session, you must implement the session interface;
<% @ Webhandler Language = " C # " Class = " Checkcookie " %>
Using System;
Using System. Web;
Using System. Web. sessionstate; // Step 1: import the namespace
Public Class Checkcookie: ihttphandler, irequiressessionstate // Step 2: implement the interface so that you can use the session as usual.
{
Public Void Processrequest (httpcontext context)
{
// ------------
}
}