![](/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.