Вы можете использовать следующий код для получения привязок:
public static IEnumerable<Binding> GetSiteBindings(Site site)
{
BindingCollection bindings = site.Bindings;
if (bindings != null)
{
foreach (Binding binding in bindings)
{
if (binding != null)
{
yield return binding;
}
}
}
yield return null;
}
Следующий код можно использовать для проверки вышеуказанного метода:
ServerManager mgr = new ServerManager();
foreach (Site s in mgr.Sites)
{
Response.Write("Site: " + s);
Response.Write("<br/>");
var siteBindings = GetSiteBindings(s);
if (siteBindings != null)
{
foreach (var binding in siteBindings)
{
if (binding != null)
{
var bindingInformation = binding.BindingInformation;
var host = binding.Host;
var endPoint = binding.EndPoint;
Response.Write("Host: " + host + ", BindingInfo: " + bindingInformation + ", EndPoint: " + endPoint);
Response.Write("<br/>");
}
}
}
Response.Write("----------------------------------");
Response.Write("<br/>");
}
Используемые пространства имен:
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Microsoft.Web.Administration" %>
Указанная сборка: Microsoft.Web.Administration
Поместить приведенный выше код в Sample.aspx для его проверки:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Microsoft.Web.Administration" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ServerManager mgr = new ServerManager();
foreach (Site s in mgr.Sites)
{
Response.Write("Site: " + s);
Response.Write("<br/>");
var siteBindings = GetSiteBindings(s);
if (siteBindings != null)
{
foreach (var binding in siteBindings)
{
if (binding != null)
{
var bindingInformation = binding.BindingInformation;
var host = binding.Host;
var endPoint = binding.EndPoint;
Response.Write("Host: " + host + ", BindingInfo: " + bindingInformation + ", EndPoint: " + endPoint);
Response.Write("<br/>");
}
}
}
Response.Write("----------------------------------");
Response.Write("<br/>");
}
}
public static IEnumerable<Binding> GetSiteBindings(Site site)
{
BindingCollection bindings = site.Bindings;
if (bindings != null)
{
foreach (Binding binding in bindings)
{
if (binding != null)
{
yield return binding;
}
}
}
yield return null;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="HtmlForm" runat="server">
<div>
</div>
</form>
</body>
</html>
даст вам вывод, как это: