c# - 当 HttpContext.Current 为空时,如何在 Elmah 的 ErrorMail_Mailing 事件中的 C# 中获取服务器变量(或至少客户端 IP 地址)?

标签 c# null elmah httpcontext request.servervariables

我正在编写一些错误处理代码,我想确定它是否是本地连接(开发人员)。通常我会查看 HttpContext.Current.Request.ServerVariables 但是在错误处理代码中如果身份验证过期 HttpContext.Current 为空。

HttpContext.Current 为 null 时,我该如何获取服务器变量——或者至少是启动请求的客户端的 IP 地址——这样我就可以确定它是否开发人员是否在他们自己的本地服务器上。

更新:我能够在 elmah 传入的 ErrorMailEventArgs 参数中检索到相关的服务器变量,特别是 errorMailEventArgs.Error.ServerVariables。

最佳答案

我能够在 elmah 传入的 ErrorMailEventArgs 参数中检索相关的服务器变量,特别是 errorMailEventArgs.Error.ServerVariables

关于c# - 当 HttpContext.Current 为空时,如何在 Elmah 的 ErrorMail_Mailing 事件中的 C# 中获取服务器变量(或至少客户端 IP 地址)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587040/

相关文章:

c# - SqlDataReader 对象的内联空检查

asp.net-mvc - 将 Elmah 与 WebApi 一起使用时会记录两次错误

c# - Azure Blob 存储批量更新。可能的?

Java 打印 "null"for String reference != to null

c# - EF5 Model-First、DBContext代码生成和派生类

java - 检查 Set 是否不包含 null 的好方法

asp.net - 我现在可以在 ASP.Net Azure 应用程序中实现类似 Elmah 的功能而不需要 Elmah 吗?

c# - Elmah.MVC 设置

c# - 多个 C# 应用程序可以使用一个 App.Config 文件吗?

c# - 如何在我的 C# 字符串中创建回车符