我正在编写一些错误处理代码,我想确定它是否是本地连接(开发人员)。通常我会查看 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/