最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ashx中使用session的方法(獲取session值)

 更新時間:2013年12月26日 15:49:37   作者:  
ashx中獲取session值的方法,大家參考使用吧

WEB開發(fā),在一般處理程序中,很容易得到 Request和Response對象,如:

復制代碼 代碼如下:

HttpRequest _request = context.Request;

HttpResponse _response = context.Response;

但是要得到 Session的值就沒有那么簡單了。

比如如果要在ashx得到保存在Session中的登錄用戶信息 Session["LoginUser"]

如果僅僅使用 context.Session["LoginUser"] 的話,是會報 “未將對象引用設置到對象的實例”的異常!

具體要使用下列方法:

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace DtlCalendar.Mobile.Site.Manage
{
    /// <summary>
    /// DelApk 的摘要說明
    /// </summary>
    public class DelApk : IHttpHandler, IReadOnlySessionState
    {
        // IReadOnlySessionState :只讀訪問Session
        // IRequiresSessionState :讀寫訪問Session
        public void ProcessRequest(HttpContext context)
        {
            string strID = context.Request["id"];
            context.Response.Clear();
            context.Response.ContentType = "text/plain";
            int id;
            string user;
            if (int.TryParse(strID, out id) && IsLoged(context, out user))
            {
                string reslt = DataProvider.MobileDataProvider.CreateInstance().DelMApk(id).ToString();
                BLL.LogOprHelper.Instance.InsertMLog(user, BLL.LogOpr.Delete, "DelApk result:" + reslt);
                context.Response.Write(reslt);
            }
            else
            {
                BLL.LogOprHelper.Instance.InsertMLog(strID, BLL.LogOpr.Delete, "DelApk result:-1");
                context.Response.Write("-1");
            }
        }

        private bool IsLoged(HttpContext context, out string user)
        {
            BLL.User _User;
            if (context.Session["LoginUser"] != null)
            {
                _User = context.Session["LoginUser"] as BLL.User;
                if (_User != null)
                {
                    user = _User.Account;
                    return true;
                }
            }
            user = string.Empty;
            return false;
        }

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

相關文章

最新評論

巢湖市| 临武县| 岚皋县| 浦县| 廊坊市| 平武县| 兴义市| 米林县| 赤峰市| 望都县| 司法| 平安县| 天镇县| 宜兴市| 孙吴县| 旅游| 贵阳市| 罗江县| 余干县| 上高县| 厦门市| 翼城县| 通城县| 绥中县| 区。| 远安县| 彩票| 平度市| 时尚| 宝丰县| 芜湖县| 清涧县| 莱芜市| 革吉县| 泗洪县| 沙雅县| 漳平市| 温宿县| 甘谷县| 资溪县| 安徽省|