2

我关注此帖:DataTable using Server Side Processing
里面default.aspx,我使用调用.ashx通过引用通用处理程序(.ashx)在Asp.net

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

Page_Loaddefaut.aspx事件:

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

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

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

回答

4

要进入里面我用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"]; 
    } 
} 

Ofcourse设置会话Employee对象,对Page_Load事件的defaut.aspx

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

相关问题