using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Configuration;
using System.Web.Security;
using Srm.Model.Authority;
/// <summary>
/// Online 的摘要说明
/// </summary>
public class Online : Page
{
。。
。。 /// <summary>
/// 把已经登陆的帐号添加到Application["OnlineUser"]
/// </summary>
public void AddAccountToApplication(Account account)
{
Hashtable hash = (Hashtable)Application["OnlineUser"]; //这句报错!!!!!
if (hash == null) hash = new Hashtable(); if (_canReLogin == "0")
//如果不允许重复登陆,hash表个键值是Session.SessionID
hash[Session.SessionID] = account.AccountId;
if (_canReLogin == "1")
//如果不允许重复登陆,hash表个键值是account.AccountId
hash[Session.SessionID] = Session.SessionID;
Application["OnlineUser"] = hash;
}}
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Configuration;
using System.Web.Security;
using Srm.Model.Authority;
/// <summary>
/// Online 的摘要说明
/// </summary>
public class Online : Page
{
。。
。。 /// <summary>
/// 把已经登陆的帐号添加到Application["OnlineUser"]
/// </summary>
public void AddAccountToApplication(Account account)
{
Hashtable hash = (Hashtable)Application["OnlineUser"]; //这句报错!!!!!
if (hash == null) hash = new Hashtable(); if (_canReLogin == "0")
//如果不允许重复登陆,hash表个键值是Session.SessionID
hash[Session.SessionID] = account.AccountId;
if (_canReLogin == "1")
//如果不允许重复登陆,hash表个键值是account.AccountId
hash[Session.SessionID] = Session.SessionID;
Application["OnlineUser"] = hash;
}}
if (hash == null) hash = new Hashtable();---你的做法不对,先判断引用是否为null,然后才能进行类型转换:
object obj = Application["OnlineUser"]; //这句报错!!!!!
if (obj== null) HashTable hash = new Hashtable();或者使用 as :
Hashtable hash = Application["OnlineUser"] as HashTable;
if (hash == null) hash = new Hashtable();
{
public System.Web.SessionState.HttpSessionState Session;
public System.Web.HttpResponse Response;
public System.Web.HttpServerUtility Server;
public System.Web.HttpRequest Request;
public System.Web.HttpApplication application;
public void abc()
{
System.Web.HttpApplicationState mya = HttpContext.Current.Application;
System.Web.SessionState.HttpSessionState mys = HttpContext.Current.Session;
..... }
}
System.Web.SessionState.HttpSessionState mys = HttpContext.Current.Session;