ASP.NET:كيفية الوصول إلى الدورة من المسؤول ؟ [مكررة]
-
21-08-2019 - |
سؤال
هذا السؤال سبق الجواب هنا:
أنا في محاولة لتخزين بعض القيم في الدورة من معالج الصفحة, قبل أن أفعل إعادة توجيه إلى 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);
}
لا تنتمي إلى StackOverflow