【发布时间】:2018-03-28 15:38:03
【问题描述】:
我在做 C# WCF,我得改编一段代码。
基本代码包含:
public override void OnActionExecuting(HttpActionContext actionContext)
{
string ipAddress = HttpContext.Current.Request.UserHostAddress;
WinEventLog.logInfo("Connection from : " + ipAddress);
bool test = IsIpAddressAllowed(ipAddress.Trim());
[..]
}
private bool IsIpAddressAllowed(string IpAddress)
{
[..]
}
但在 WCF 中,我无法获得 HttpContext.Current.Request.UserHostAddress。
我的 WCF 代码是:
[ServiceContract]
[RequiredParametersBehavior]
public interface IMyService
{
[OperationContract]
String Request(String environment, String request);
}
如何在我的函数Request 中获取用户IP 地址?
【问题讨论】:
-
我同意 - 重复问题的答案取决于版本。