【问题标题】:Pass By Reference to Generic Handler(.ashx) in Asp.net在 Asp.net 中通过引用传递到通用处理程序(.ashx)
【发布时间】:2012-10-09 17:59:33
【问题描述】:

我关注了这个帖子:DataTable using Server Side Processing.
default.aspx 内部,我使用以下方式调用.ashx

<script type="text/javascript">
$(function () {
    $('#example').dataTable({
        'bProcessing': true,
        'bServerSide': true,
        'sAjaxSource': '/data.ashx'
    });
});

defaut.aspxPage_Load 事件上:

Employee emp=new Employee();
emp.name="abc";
emp.addr="pqr";
emp.phone="123";

其中Employee 是类的名称。
如何将员工对象传递给Data.ashx

我尝试使用HttpContext.Current.Session,但将Session 对象显示为null
请帮忙。

【问题讨论】:

    标签: datatable parameter-passing pass-by-reference generic-handler


    【解决方案1】:

    为了访问会话内部,我使用了IRequiresSessionState 接口,如下所示:

    public class Data : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
         public void ProcessRequest(HttpContext context)
         {
             // get Employee object from session here
             Employee emp =(Employee)HttpContext.Current.Session["employee"];
         }
    }
    

    当然要在会话中设置一个 Employee 对象,在 defaut.aspxPage_Load 事件上:

    Employee emp=new Employee();
    emp.name="abc";
    emp.addr="pqr";
    emp.phone="123";
    
    HttpContext.Current.Session["employee"]=emp;
    

    注意:
    有两个接口可用于访问通用处理程序中的HttpSession

    1. IRequiresSessionState
      使用这个接口,我们可以读取和写入会话变量。

    2. IReadOnlySessionState
      使用此接口,我们只能读取而不能写入或编辑会话变量。

    欲了解更多信息,请查看此链接:IRequiresSessionState vs IReadOnlySessionState

    【讨论】:

      猜你喜欢
      • 2010-10-12
      • 2011-04-11
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      相关资源
      最近更新 更多