zoukankan      html  css  js  c++  java
  • 在ashx文件中使用Session和QueryString

    来源于:http://www.cnblogs.com/luzx/archive/2011/05/03/2035416.html

    有三点需要注意:

    1.命名空间中要加入using System.Web.SessionState;

    2.接口名要加入IRequiresSessionState或IReadOnlySessionState;

    3.不管是Session还是QueryString都要通过HttpContext来获取。

    具体代码如下:

    <%@ WebHandler Language="C#" Class="UploadHandler" %>
    
    using System;
    using System.IO;
    using System.Net;
    using System.Web;
    using System.Web.SessionState;
    
    public class UploadHandler : IHttpHandler, IRequiresSessionState
    {
        
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.Charset = "utf-8";
    
            string str1 = context.Session["aaa"].ToString();
            string str2 = context.Request.QueryString["bbb"].ToString();
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
  • 相关阅读:
    10.28
    10.29
    11.05周四
    数据库增删改查
    11.03Tuesday
    11.10
    连接数据库
    10.30
    11.04周三
    10.27
  • 原文地址:https://www.cnblogs.com/wyf/p/2035475.html
Copyright © 2011-2022 走看看