У меня есть приложение ASP.NET и dll, которое расширяет IHttpModule. Я использовал метод ниже, чтобы сохранить переменные сессии в HttpContext черезДоступ к переменным сеанса сеанса в C#
public class Handler : IHttpModule,IRequiresSessionState
{
public void Init(HttpApplication httpApp)
{
httpApp.PreRequestHandlerExecute += new EventHandler(PreRequestHandlerExecute);
}
public void PreRequestHandlerExecute(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
context.Session["myvariable"] = "Gowtham";
}
}
и в моей странице Default.aspx asp.net я использовал код retrive значения в качестве
public partial class _Default : System.Web.UI.Page, IRequiresSessionState
{
protected void Page_Load(object sender, EventArgs e)
{
String token = Context.Session["myvariable"].ToString();
}
}
я получаю сообщение об ошибке Ответная реакция как
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.
в целях обеспечения того, магазин переменных в сессии я пересек проверку с помощью следующего метода класса в обработчике после сохранения значения в сессии в качестве
string ss = context.Session["myvariable"].ToString();
он хорошо выполнен и получил значение из сеанса.
Возможный дубликат [Доступ к данным сеанса связи из другого потока] (http://stackoverflow.com/questions/13036928/access-session-data-from-another-thread) –