婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > ashx中使用session的方法(獲取session值)

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

熱門標簽:福州人工智能電銷機器人加盟 宿遷智能外呼系統排名 電銷機器人 數據 怎樣給陜西地圖標注顏色 ai電銷機器人對貸款有幫助嗎 廣州銷售外呼系統定制 云狐人工智能電話機器人 地圖標注多少錢一張 400電話辦理信任翰諾科技

WEB開發,在一般處理程序中,很容易得到 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;
            }
        }
    }
}

您可能感興趣的文章:
  • ASP.NET ASHX中獲得Session的方法
  • Asp.net在ashx文件中處理Session問題解決方法
  • 在ashx文件中使用session的解決思路
  • ashx介紹以及ashx文件與aspx文件之間的區別
  • ashx文件的使用小結
  • aspx與ascx,ashx的用法總結
  • 后綴為 ashx 與 axd 的文件區別淺析
  • 基于.NET中:自動將請求參數綁定到ASPX、ASHX和MVC的方法(菜鳥必看)
  • *.ashx文件不能訪問Session值的解決方法

標簽:焦作 綿陽 延安 大興安嶺 黃南 宜春 曲靖 新疆

巨人網絡通訊聲明:本文標題《ashx中使用session的方法(獲取session值)》,本文關鍵詞  ashx,中,使用,session,的,方法,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ashx中使用session的方法(獲取session值)》相關的同類信息!
  • 本頁收集關于ashx中使用session的方法(獲取session值)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 得荣县| 卢湾区| 丰台区| 石屏县| 青阳县| 道孚县| 休宁县| 凤凰县| 保定市| 台山市| 井陉县| 甘泉县| 万盛区| 乐业县| 江华| 申扎县| 合山市| 昌江| 竹山县| 杭锦后旗| 越西县| 怀远县| 泰来县| 军事| 修武县| 基隆市| 徐水县| 疏附县| 封开县| 阜宁县| 章丘市| 万宁市| 晋宁县| 曲阜市| 涿州市| 纳雍县| 道真| 嘉鱼县| 香格里拉县| 乳源| 武强县|