ASP.NET:global.asax中的Access Session变量
发布时间:2020-12-16 04:38:03 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET应用程序,在Global.asax’应用程序错误事件中,我正在调用一个跟踪/记录错误的方法.我想在这里使用会话变量内容.我使用下面的代码 void Application_Error(object sender,EventArgs e){ //get reference to the source of the exception chain
我有一个ASP.NET应用程序,在Global.asax’应用程序错误事件中,我正在调用一个跟踪/记录错误的方法.我想在这里使用会话变量内容.我使用下面的代码
void Application_Error(object sender,EventArgs e) { //get reference to the source of the exception chain Exception ex = Server.GetLastError().GetBaseException(); //log the details of the exception and page state to the //Windows 2000 Event Log GUI.MailClass objMail = new GUI.MailClass(); string strError = "MESSAGE: " + ex.Message + "<br><br><br>" + "SOURCE: " + ex.Source + "<br>FORM: " + Request.Form.ToString() + "<br>QUERYSTRING: " + Request.QueryString.ToString() + "<br>TARGETSITE: " + ex.TargetSite + "<br>STACKTRACE: " + ex.StackTrace; if (System.Web.HttpContext.Current.Session["trCustomerEmail"] != null) { strError = "Customer Email : " + Session["trCustomerEmail"].ToString() +"<br />"+ strError; } //Call a method to send the error details as an Email objMail.sendMail("test@gmail.com","myid@gmail.com","Error in " + Request.Form.ToString(),strError,2); } 我在访问会话变量的代码行中出现错误.Visual Studio告诉我
如何摆脱这个?有什么想法吗? 提前致谢 解决方法
如果你这样做它应该工作:
strError = System.Web.HttpContext.Current.Session["trCustomerEmail"] 因为这就是我自己做的事情. 你的意思是什么:Visual Studio告诉“会话在这种情况下不可用”?您是否收到编译器错误或运行时异常? 如果确实存在当前的HttpContext和Session,您可以尝试更具防御性并进行测试: if (HttpContext.Current != null && HttpContext.Current.Session != null) { strError = HttpContext.Current.Session["trCustomerEmail"] } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 使用单元测试在asp.net mvc中验证重定向
- asp.net-mvc – 用于拆分日期时间字段的ASP.NET MVC 2自定义
- C#进阶系列——WebApi 接口参数不再困惑:传参详解
- 最好的asp.net日历/日程安排组件?
- asp.net – IE10条件IE注释<! - >功能启用程序
- ASP.NET IIS服务器端打印失败
- asp.net-mvc – 您对Telerik Extensions for MVC有何看法?
- asp.net-mvc – 在Elastic Beanstalk Web.config中访问ASP.
- asp.net-mvc – 在ASP.NET MVC中指定只读会话
- asp.net – 更新查询似乎删除了备注字段
推荐文章
站长推荐
- 组合密钥资源REST服务
- asp.net-mvc-3 – 另一个数据库实例RavenDB MVC3
- asp.net – 在Load事件中使用LoadControl的陷阱
- 在asp.net mvc应用程序中从Javascript访问C#变量
- asp.net-mvc – 用于json嵌套数组的MVC3绑定
- asp.net – ScriptResource.axd和.Net 4
- asp.net-core – ASP.NET核心视图组件位置是否有
- asp.net-mvc-3 – MVC Razor – 创建/编辑视图最
- asp.net – 我对Html.TextBoxFor的工作原理有什么
- asp.net – 如何在没有代码隐藏文件的情况下在VB
热点阅读