![](/img/trans.png)
[英]How to get the Local IP of an ASP.net site when each site running on IIS is assigned its own IP?
[英]How to get the correct local address URI when hosting IIS site on multiple bindings?
我已经在IIS中使用多个端口绑定配置了一个简单的服务。 无论调用哪个端口,当前通道的本地地址始终是相同的。
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class TestService : ITestService
{
public string Test()
{
return OperationContext.Current.Channel.LocalAddress.Uri.Port.ToString();
}
}
调用testHost2:7772
>返回7772
调用testHost1:7771
>也返回7772
您可以使用以下代码使用WCF获取主机名和端口:
var test = OperationContext.Current.Host.BaseAddresses[0].Authority;
要么
Uri uri = OperationContext.Current.IncomingMessageHeaders.To ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.