请求在此上下文中不可用的解决办法

在类文件里应用: Response 、 Request 、Session

要写全部路径    

System.Web.HttpContext.Current.Response

System.Web.HttpContext.Current.Request

System.Web.HttpContext.Current.Session 

阅读更多
换一批

请求在此上下文中不可用

08-22

请求在此上下文中不可用 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Web.HttpException: 请求在此上下文中不可用rnrn源错误: rnrnrn行 9: rn行 10: 'Dim e_companyid As String = Request.Cookies("e_companyid").Valuern行 11: Dim e_companyid As String = Request.Cookies("dm").Valuern行 12: rn行 13: Protected Sub content1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles content1.Loadrn rnrn源文件: E:\nengyuan\aa\tb4.aspx.vb 行: 11 rnrn堆栈跟踪: rnrnrn[HttpException (0x80004005): 请求在此上下文中不可用]rn System.Web.UI.Page.get_Request() +2077605rn tb4..ctor() in E:\nengyuan\aa\tb4.aspx.vb:11rn ASP.tb4_aspx..ctor() in E:\nengyuan\aa\tb4.aspx.vb:912304rn __ASP.FastObjectFactory_app_web_igzmi_6v.Create_ASP_tb4_aspx() +38rn System.Web.Compilation.BuildResultCompiledType.CreateInstance() +49rn System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +115rn System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31rn System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40rn System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +139rn System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128rn System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +161rnrn rn

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

08-23

我写了个类(Library_oa)取cookies,然后在页面中取出来显示,一运行就提示说“System.Web.HttpException: 请求在此上下文中不可用”,cookies值肯定是有的。请高手帮我解决,谢谢!rn附带错误文件:rn1、类文件:rnusing System;rnusing System.Text;rnusing System.Web;rnusing System.Web.UI;rnusing System.Web.Security;rnusing System.Configuration;rnrnnamespace Library_oarnrn /// rn /// GetUser 的摘要说明。rn /// rn public class GetUserrn rn private string PassCode = "";rnrn public System.Web.UI.Page Page=new System.Web.UI.Page();rn rn public GetUser()rn rn //rn // TODO: 在此处添加构造函数逻辑rn //rn //string uss=userState.UserInfo.GetValue("WorkNo");rn rn rnrn public string GetId()rn rn try rn rn rn if (Page.Request.Cookies["GoodwaySoftware"].ToString()!=null)rn rn if (Page.Request.Cookies["GoodwaySoftware"].Value.Trim().Length > 0)rn rn PassCode = Page.Request.Cookies["GoodwaySoftware"].Value.Trim();rn rn rn rn catch(Exception ex)rn rn throw new Exception(ex.Message);rn rnrn return PassCode;rn rn rnrnrn2、调用页面rnusing System;rnusing System.Collections;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Web;rnusing System.Web.SessionState;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnusing System.Web.UI.HtmlControls;rnrnusing Library_oa;rnrnnamespace yth_oarnrn /// rn /// test 的摘要说明。rn /// rn public class test : System.Web.UI.Pagern rn protected System.Web.UI.WebControls.Label Label1;rn rn private void Page_Load(object sender, System.EventArgs e)rn rn tryrn rn GetUser u= new GetUser();rn string uss=u.GetId();rn rn Label1.Text=uss;rn rn catch(Exception ex)rn rn Response.Write(ex.Message); rn rn rn rnrn #region Web 窗体设计器生成的代码rn override protected void OnInit(EventArgs e)rn rn //rn // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。rn //rn InitializeComponent();rn base.OnInit(e);rn rn rn /// rn /// 设计器支持所需的方法 - 不要使用代码编辑器修改rn /// 此方法的内容。rn /// rn private void InitializeComponent()rn rn this.Load += new System.EventHandler(this.Page_Load);rnrn rn #endregionrn rnrn

没有更多推荐了,返回首页