ASP.NET:global.asax中的Access Session变量
发布时间:2020-05-24 09:31:05 所属栏目: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 – 如何在Visual Studio中添加NUnit
- 为什么在手动刷新响应时ASP.NET将使用Transfer-Encoding头替
- ASP.NET Web API将http响应转换为json数组
- asp.net-mvc-3 – asp.net mvc的telerik grid的开源替代品?
- 在Asp.net中运行外部可执行文件的内存限制
- asp.net-mvc – ASP.NET MVC UpdateModel()方法如何工作?
- 在ASP.NET网站中使用单例连接是一个好主意
- 动态加载asp.net网站中的用户控件(ascx)
- attributes – 利用属性版本控制在Swagger中利用MultipleAp
- 嵌套的ASP.NET’应用程序’在IIS内继承父配置值?
推荐文章
站长推荐
- asp.net-web-api – 密码更改时如何使OAuth令牌无
- asp.net – RenderBody和RenderSection之间的区别
- Asp.net核心IIS Express.如何查看日志消息?
- 充分利用ASP.NET的三种缓存提高站点性能的注意方
- ASP.NET MVC:使用LINQ To SQL获取表单复选框到多
- asp.net-mvc – 避免@html.checkboxfor的foreach
- asp.net – 如何确定用户的浏览器是否可以查看PD
- 在asp.net中将用户变量存储在数据库与会话中
- asp.net-core – CoreCLR中的MD5CryptoServicePr
- asp.net – %%和%=%之间有什么区别?
热点阅读
