【发布时间】:2009-03-16 13:09:59
【问题描述】:
我们有一个在 IIS7 中运行的 WCF (.NET 3.5 SP1) 服务,它被标记为允许 ASP.NET 兼容模式,因此我们可以访问HttpContext.Current:
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
但是,当尝试访问任何服务器变量时,它会抛出 ArgumentException:
System.ArgumentException: Value does not fall within the expected range.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
at System.Web.HttpRequest.get_UserHostAddress()
例如以下任何行都会引发此异常:
ha = HttpContext.Current.Request.UserHostAddress;
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
us = HttpContext.Current.Request.UserAgent;
这似乎是内部框架调用的结果,这意味着调用代码没有错误。
大概是我们的配置中的某些东西导致了这个问题,但我不知道是什么。有任何想法吗?或者任何想法我可以如何检索这三位数据(不幸的是,它们似乎没有被 WCF 本机公开)。
【问题讨论】:
标签: wcf