zoukankan      html  css  js  c++  java
  • ashx文件中使用session提示“未将对象引用设置到对象的实例”

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data;
    using System.Web.SessionState;
    namespace friends {
        /// <summary>
        /// Handler 的摘要说明
        /// </summary>
        public class Handler : IHttpHandler, IRequiresSessionState {

            public void ProcessRequest(HttpContext context) {
                context.Response.ContentType = "text/plain";


     

    在使用一般处理程序时,会用session,但是在ashx文件中,默认时,无法向session创建新的键值,写了就会报错,就会提示:“未将对象引用设置到对象的实例”  

    那么,将此ashx文件类继承一个接口,如以下所示:

    System.Web.SessionState.IReadOnlySessionState 为只读会话的接口 继承这个接口,只能读取session 但不能为session赋值
    System.Web.SessionState.IRequiresSessionState 为可读可写的 继承这个接口,即可读取session的值,也可以对其赋值,所以在一般处理程序中,继承这个接口
  • 相关阅读:
    [LeetCode] 67. 二进制求和
    [LeetCode] 66. 加一
    [LeetCode] 65. 有效数字
    [LeetCode] 63. 不同路径 II
    [LeetCode] 64. 最小路径和
    [LeetCode] 61. 旋转链表
    [LeetCode] 62. 不同路径
    [LeetCode] 59. 螺旋矩阵 II
    [LeetCode] 60. 第k个排列
    [LeetCode] 58. 最后一个单词的长度
  • 原文地址:https://www.cnblogs.com/tiancai/p/3729463.html
Copyright © 2011-2022 走看看