我们有一个在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本机公开)。