سؤال

هذا السؤال سبق الجواب هنا:

أنا في محاولة لتخزين بعض القيم في الدورة من معالج الصفحة, قبل أن أفعل إعادة توجيه إلى WebForms الصفحة التي سوف تلتقط الدورة قيم ما قبل ملء نموذج ويب:

public class Handler : IHttpHandler
{
   public void ProcessRequest(HttpContext context)
   {
      ...
      context.Session["StackOverflow"] = "overflowing";
      context.Response.Redirect("~/AnotherPage.aspx");
      ...
   }
   ...
 }

إلا context.Session كائن باطل.

كيف يمكنني الوصول إلى حالة جلسة من المسؤول ؟

هل كانت مفيدة؟

المحلول

تنفيذ النظام.ويب.SessionState.IRequiresSessionState واجهة

public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
{   
  public void ProcessRequest(HttpContext context)  
  {      
    context.Session["StackOverflow"] = "overflowing";      
    context.Response.Redirect("~/AnotherPage.aspx");      
  }

}

نصائح أخرى

تنفيذ IRequiresSessionState

لا تنفيذ iRequiresSessionState حل هذا ؟

ماذا عن القيام IHttpModule بدلا الغالب BeginRequest?

    public void Init(HttpApplication application)
    {
        application.BeginRequest += new EventHandler(context_BeginRequest);
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top