2012-10-18 36 views
0

在ashx: 我把數據放在實體列表中&分配給會話。如何從通用處理程序訪問會話

context.Session["objList"] = myEntityCollection; 

我想通過迴應得到本次會議;在代碼後面。 它是如何實現的?

context.Response.ContentType = ??? 
..... 
context.Response.Write(context.Session["objList"]); 

回答

0

序列化對象JSON,返回序列化的字符串響應和使用application/json的ContentType

2

嗨,如果我理解正確。要訪問ashx文件中的會話數據,您需要實現接口IRequiresSessionState

public class ExampleHttpHandler : IHttpHandler, IRequiresSessionState 
{ 
    public bool IsReusable 
    { 
     get 
     { 
      return false; 
     } 
    } 

    public void ProcessRequest(HttpContext context) 
    {  
     context.Session["test"] = "test"; 
     context.Response.Write(context.Session["test"]); 
    } 
} 
+0

感謝您的回覆。但我已經在使用它了。問題在於我沒有獲取對象,而是在後面的代碼中獲取對象的名稱。 – mike44