紧急求助:“System.Web.HttpException: 请求在此上下文中不可用”解决办法

hahan 2007-08-23 10:35:10
我写了个类(Library_oa)取cookies,然后在页面中取出来显示,一运行就提示说“System.Web.HttpException: 请求在此上下文中不可用”,cookies值肯定是有的。请高手帮我解决,谢谢!
附带错误文件:
1、类文件:
using System;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Configuration;

namespace Library_oa
{
/// <summary>
/// GetUser 的摘要说明。
/// </summary>
public class GetUser
{
private string PassCode = "";

public System.Web.UI.Page Page=new System.Web.UI.Page();

public GetUser()
{
//
// TODO: 在此处添加构造函数逻辑
//
//string uss=userState.UserInfo.GetValue("WorkNo");

}

public string GetId()
{
try
{

if (Page.Request.Cookies["GoodwaySoftware"].ToString()!=null)
{
if (Page.Request.Cookies["GoodwaySoftware"].Value.Trim().Length > 0)
{
PassCode = Page.Request.Cookies["GoodwaySoftware"].Value.Trim();
}
}
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}

return PassCode;
}
}
}

2、调用页面
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Library_oa;

namespace yth_oa
{
/// <summary>
/// test 的摘要说明。
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
try
{
GetUser u= new GetUser();
string uss=u.GetId();

Label1.Text=uss;
}
catch(Exception ex)
{
Response.Write(ex.Message);
}

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
...全文
1986 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
我的我的 2011-08-01
  • 打赏
  • 举报
回复
按照3楼方法已经解决
shalen520 2007-08-23
  • 打赏
  • 举报
回复
自己new的page哪有HttpContext哦

System.Web.HttpContext.Current
lisbates27 2007-08-23
  • 打赏
  • 举报
回复
up
BearRui 2007-08-23
  • 打赏
  • 举报
回复
GetUser类中
Page.Request.Cookies改成HttpContext.Current.Request.Cookies
zjhphc 2007-08-23
  • 打赏
  • 举报
回复
是不是应该用HttpContext.Current

110,547

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧