1. 程式人生 > >ashx頁面怎麽調用Handler的Session

ashx頁面怎麽調用Handler的Session

OS http tar public pre sys ble AS ssi

aspx裏面直接可以用Session["Name"]進行賦值和取值,ashx中就得繼承接口IRequiresSessionState。然後使用!

實現:

public class UserInfo : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        var userinfo = context.Session["userinfo"];
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

  

下面的代碼示例檢查當前的 HTTP Handler 屬性來確定是否需要讀取和寫入訪問為會話狀態的值。

bool requiresSession = false;if (Context.Handler is IRequiresSessionState)
  requiresSession = true;
 

文章引用:http://code365.club/Article?id=19

ashx頁面怎麽調用Handler的Session