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

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

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

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

復(fù)制代碼 代碼如下:

HttpRequest _request = context.Request;

HttpResponse _response = context.Response;

但是要得到 Session的值就沒(méi)有那么簡(jiǎn)單了。

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

如果僅僅使用 context.Session["LoginUser"] 的話(huà),是會(huì)報(bào) “未將對(duì)象引用設(shè)置到對(duì)象的實(shí)例”的異常!

具體要使用下列方法:

復(fù)制代碼 代碼如下:

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

namespace DtlCalendar.Mobile.Site.Manage
{
    /// <summary>
    /// DelApk 的摘要說(shuō)明
    /// </summary>
    public class DelApk : IHttpHandler, IReadOnlySessionState
    {
        // IReadOnlySessionState :只讀訪(fǎng)問(wèn)Session
        // IRequiresSessionState :讀寫(xiě)訪(fǎng)問(wèn)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;
            }
        }
    }
}

相關(guān)文章

最新評(píng)論

讷河市| 谢通门县| 吕梁市| 卓尼县| 沙田区| 石嘴山市| 包头市| 三都| 郴州市| 湘乡市| 东山县| 芦溪县| 武功县| 永善县| 治县。| 正定县| 吕梁市| 遵义市| 海兴县| 栖霞市| 承德市| 潜江市| 黄骅市| 建平县| 仙桃市| 资源县| 民乐县| 塔城市| 西贡区| 永昌县| 安图县| 江都市| 大洼县| 金秀| 乃东县| 华安县| 正阳县| 芜湖县| 固安县| 汨罗市| 永年县|