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

在类文件里应用: 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

请求在此上下文中不可用问题,控件作为参数

10-30

写了一个公共函数放在app_code中,但是在其他页面调用时报错:System.Web.HttpException: 请求在此上下文中不可用,求解。rnrnapp_code:bll.cs 主要是想把Repeater之类的控件作为函数参数用rnrn[code=csharp]rn public void Paging(int totalrecord, int PageSize, int DigitNo, Control pagediv, Repeater rpt,string table,string id)rn rn int CurrentPage, PageStart, PageEnd, TotalPage;rn //****************************************//计算总页数rn int pn1 = totalrecord / PageSize, pn2 = totalrecord % PageSize;rn if (pn2 != 0)rn TotalPage = pn1 + 1;rn elsern if (pn1 == 0)rn TotalPage = 1;rn elsern TotalPage = pn1;rn //****************************************rn if (Request.QueryString["page"] == null)//获取当前页码rn CurrentPage = 1;rn elsern CurrentPage = Convert.ToInt16(Request.QueryString["page"]);rnrn PageStart = 1;//起始数字逻辑判断rn if (CurrentPage >= DigitNo + 2)rn PageStart = CurrentPage - DigitNo;rnrn PageEnd = CurrentPage + DigitNo;//结束数字逻辑判断rn if (PageEnd > TotalPage + 1)rn PageEnd = TotalPage + 1;rnrn if (CurrentPage != 1)rn rn HyperLink FP = new HyperLink();//生成首页文字按钮rn FP.Text = "首页"; FP.Style["color"] = "#06C";rn FP.NavigateUrl = "?page=1";rn HyperLink PP = new HyperLink();//生成上一页文字按钮rn PP.Text = "上一页"; PP.Style["color"] = "#06C";rn PP.NavigateUrl = "?page=" + (CurrentPage - 1);rn pagediv.Controls.Add(FP);//将文字分页按钮装入pagediv容器rn pagediv.Controls.Add(PP);rn rnrn for (int i = PageStart; i < PageEnd; i++)//生成中间数字按钮,并进行相关判断rn rn HyperLink no = new HyperLink();rn no.Text = i.ToString();rn no.NavigateUrl = "?page=" + i;rn no.CssClass = "pagediv";rn if (i == CurrentPage)rn rn no.Enabled = false;rn no.CssClass = "current";rn rn pagediv.Controls.Add(no);//将数字分页按钮装入pagediv容器rn rnrn if (CurrentPage != TotalPage)rn rn HyperLink LP = new HyperLink();//生成尾页文字按钮rn LP.Text = "尾页"; LP.Style["color"] = "#06C";rn LP.NavigateUrl = "?page=" + TotalPage;rn HyperLink NP = new HyperLink();//生成下一页文字按钮rn NP.Text = "下一页"; NP.Style["color"] = "#06C";rn NP.NavigateUrl = "?page=" + (CurrentPage + 1);rn pagediv.Controls.Add(NP);//将文字分页按钮装入pagediv容器rn pagediv.Controls.Add(LP);rn rn //绑定数据库******************************降序排列rn int StartIndex = (CurrentPage - 1) * PageSize + 1;rn rpt.DataSource = DT("select top " + PageSize + " * from "+table+" where "+id+" <= (select min("+id+") from (select top " + StartIndex + " " + id + " from "+table+" order by "+id+" desc)) order by "+id+" desc");rn rpt.DataBind();rn rn[/code]rnrnrn调用页面:.aspx.csrnrn[code=csharp]rn bll bl = new bll();rn int RecordNo() return bl.CountData("select count(b_id) from bianmin"); //记录总数rnrn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rn bl.Paging(RecordNo(), 2, 5, pagediv, Repeater1, "bianmin", "b_id");rn rn rn[/code]

帮我看看,为什么老是提示“请求在此上下文中不可用

08-04

异常详细信息: System.Web.HttpException: 请求在此上下文中不可用rnrn源错误: rnrnrn行 25: public string newInit()rn行 26: rn行 27: if(Request.Cookies["iscookies"]==null)rn行 28: rn行 29: HttpCookie MyCookie = new HttpCookie("iscookies");rn rnrn源文件: c:\inetpub\wwwroot\fcbbs\inc\const.aspx.cs 行: 27 rnrnrn我的源文件:rnrnusing 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;rnusing Fcbbs.Components;rnnamespace Fcbbs.incrnrn /// rn /// _const 的摘要说明。rn /// rn /// rnrn public class _const : System.Web.UI.Pagern rn Database db=new Database();rn Fun fun=new Fun();rn public static string Forum_sn="Fcbbs";rn rn public string newInit()rn rn if(Request.Cookies["iscookies"]==null)rn rn HttpCookie MyCookie = new HttpCookie("iscookies");rn DateTime now = DateTime.Now;rn MyCookie.Value = "0";rn MyCookie.Expires = now.AddYears(1);rn Response.Cookies.Add(MyCookie);rn return "……";rn rn else return "已经存在!"+Request.Cookies["iscookies"].ToString();rn rn private void Page_Load(object sender, System.EventArgs e)rn rn // 在此处放置用户代码以初始化页面rn if(!Page.IsPostBack)rnrn 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 rnrnrn

vs2013 Error creating context 'spring.root': 请求在此上下文中不可用

02-25

最近在学习spring.net 就做了一个简单的用例 spring.net+nhibernate4+mvc4 可在初始化spring的时候报错。 一直没找到原因, 在非web程序下是没问题的。还望大神们指点一二。rn[img=http://img.bbs.csdn.net/upload/201502/25/1424874175_92638.png][/img]rn[img=http://img.bbs.csdn.net/upload/201502/25/1424874187_809676.png][/img]rnrn用户代码未处理 System.Configuration.ConfigurationErrorsExceptionrn HResult=-2146232062rn Message=Error creating context 'spring.root': 请求在此上下文中不可用rn Source=System.Configurationrn BareMessage=Error creating context 'spring.root': 请求在此上下文中不可用rn Line=0rn StackTrace:rn 在 System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)rn 在 System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)rn 在 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)rn 在 System.Configuration.BaseConfigurationRecord.GetSection(String configKey)rn 在 System.Web.HttpContext.GetSection(String sectionName)rn 在 System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)rn 在 System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)rn 在 System.Configuration.ConfigurationManager.GetSection(String sectionName)rn 在 Spring.Util.ConfigurationUtils.GetSection(String sectionName)rn 在 Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded()rn 在 Spring.Context.Support.ContextRegistry.GetContext()rn 在 AQS.WebClient.MvcApplication.Init() 位置 e:\工作资料\DotNet\WebClient\Global.asax.cs:行号 34rn 在 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)rn InnerException: System.Web.HttpExceptionrn HResult=-2147467259rn Message=请求在此上下文中不可用rn Source=System.Webrn ErrorCode=-2147467259rn WebEventCode=0rn StackTrace:rn 在 System.Web.HttpContext.get_Request()rn 在 Spring.Util.VirtualEnvironment.HttpRuntimeEnvironment.RewriteContext..ctor(String virtualDirectory, Boolean rebaseClientPath)rn 在 Spring.Util.VirtualEnvironment.HttpRuntimeEnvironment.RewritePath(String virtualDirectory, Boolean rebaseClientPath)rn 在 Spring.Util.VirtualEnvironment.RewritePath(String newVirtualPath, Boolean rebaseClientPath)rn 在 Spring.Util.HttpContextSwitch..ctor(String virtualDirectory)rn 在 Spring.Context.Support.WebContextHandler.InstantiateContext(IApplicationContext parent, Object configContext, String contextName, Type contextType, Boolean caseSensitive, IList`1 resources)rn 在 Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section)rn InnerException: rn

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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试