本文整理汇总了C#中WebsitePanel.Providers.Web.WebServer.GetSiteBindings方法的典型用法代码示例。如果您正苦于以下问题:C# WebServer.GetSiteBindings方法的具体用法?C# WebServer.GetSiteBindings怎么用?C# WebServer.GetSiteBindings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebsitePanel.Providers.Web.WebServer
的用法示例。
在下文中一共展示了WebServer.GetSiteBindings方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteWebSitePointer
public static int DeleteWebSitePointer(int siteItemId, int domainId, bool updateWebSite)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// load site item
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
if (siteItem == null)
return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;
// load domain item
DomainInfo domain = ServerController.GetDomain(domainId);
if (domain == null)
return BusinessErrorCodes.ERROR_DOMAIN_PACKAGE_ITEM_NOT_FOUND;
// load appropriate zone
DnsZone zone = (DnsZone)PackageController.GetPackageItem(domain.ZoneItemId);
// get zone records for the service
List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(siteItem.ServiceId);
// load web site IP address
IPAddressInfo ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
// place log record
TaskManager.StartTask("WEB_SITE", "DELETE_POINTER", siteItem.Name);
TaskManager.ItemId = siteItemId;
TaskManager.WriteParameter("Domain pointer", domain.DomainName);
try
{
if (zone != null)
{
// change DNS zone
string serviceIp = (ip != null) ? ip.ExternalIP : null;
List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(
dnsRecords, domain.DomainName, serviceIp);
try
{
DNSServer dns = new DNSServer();
ServiceProviderProxy.Init(dns, zone.ServiceId);
dns.DeleteZoneRecords(zone.Name, resourceRecords.ToArray());
}
catch(Exception ex1)
{
TaskManager.WriteError(ex1, "Error deleting DNS records");
}
}
if (updateWebSite)
{
// get existing web site bindings
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
List<ServerBinding> bindings = new List<ServerBinding>();
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
// check if web site has dedicated IP assigned
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
// update binding only for "shared" ip addresses
if (!dedicatedIp)
{
// remove host headers
List<ServerBinding> domainBindings = new List<ServerBinding>();
FillWebServerBindings(domainBindings, dnsRecords, "", domain.DomainName);
// fill to remove list
List<string> headersToRemove = new List<string>();
foreach (ServerBinding domainBinding in domainBindings)
headersToRemove.Add(domainBinding.Host);
// remove bndings
bindings.RemoveAll(b => { return headersToRemove.Contains(b.Host) && b.Port == "80"; } );
// update bindings
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
}
}
// update domain
domain.WebSiteId = 0;
ServerController.UpdateDomain(domain);
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
示例2: SwitchWebSiteToDedicatedIP
//.........这里部分代码省略.........
if (settings["PublicSharedIP"] != null)
serviceIp = settings["PublicSharedIP"].ToString();
}
ServerController.RemoveServiceDNSRecords(domain.PackageId, ResourceGroups.Web, domain, serviceIp, true);
}
// update site item
siteItem.SiteIPAddressId = addressId;
PackageController.UpdatePackageItem(siteItem);
// associate IP with web site
ServerController.AddItemIPAddress(siteItemId, ipAddressId);
string parentZone = domain.ZoneName;
if (string.IsNullOrEmpty(parentZone))
{
DomainInfo parentDomain = ServerController.GetDomain(domain.DomainItemId);
parentZone = parentDomain.DomainName;
}
AddWebSitePointer(siteItemId,
((domain.DomainName.Replace("." + parentZone, "") == parentZone) |
(domain.DomainName == parentZone))
? "" : domain.DomainName.Replace("." + parentZone, "")
, ZoneInfo.DomainId, true, true, true);
foreach (DomainInfo pointer in pointers)
{
string pointerParentZone = pointer.ZoneName;
if (string.IsNullOrEmpty(pointerParentZone))
{
DomainInfo parentDomain = ServerController.GetDomain(pointer.DomainItemId);
pointerParentZone = parentDomain.DomainName;
}
ZoneInfo = ServerController.GetDomain(pointerParentZone);
AddWebSitePointer(siteItemId,
((pointer.DomainName.Replace("." + pointerParentZone, "") == pointerParentZone) |
(pointer.DomainName == pointerParentZone))
? "" : pointer.DomainName.Replace("." + pointerParentZone, "")
, ZoneInfo.DomainId, true, true, true);
}
// load web site IP address
ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
string ipAddr = "*";
if (ip != null)
ipAddr = !String.IsNullOrEmpty(ip.InternalIP) ? ip.InternalIP : ip.ExternalIP;
newBindings = new List<ServerBinding>();
ServerBinding srvBinding = new ServerBinding(ipAddr, "80", "");
newBindings.Add(srvBinding);
foreach (ServerBinding b in web.GetSiteBindings(siteItem.SiteId))
{
if (!((b.Host == srvBinding.Host) &
(b.IP == srvBinding.IP) &
(b.Port == srvBinding.Port)))
newBindings.Add(b);
}
web.UpdateSiteBindings(siteItem.SiteId, newBindings.ToArray(), false);
if (oneSiteOnly)
{
sites = WebServerController.GetWebSites(domain.PackageId, false);
// load site item
ip = ServerController.GetIPAddress(sites[0].SiteIPAddressId);
string serviceIp = (ip != null) ? ip.ExternalIP : null;
if (string.IsNullOrEmpty(serviceIp))
{
StringDictionary settings = ServerController.GetServiceSettings(sites[0].ServiceId);
if (settings["PublicSharedIP"] != null)
serviceIp = settings["PublicSharedIP"].ToString();
}
ServerController.AddServiceDNSRecords(domain.PackageId, ResourceGroups.Web, domain, serviceIp, true);
}
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
示例3: ImporHostHeader
public static int ImporHostHeader(int userId, int packageId, int siteId)
{
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteId);
if (siteItem == null)
return -1;
// load live site from service
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
// Verify if already exists
List<DomainInfo> domains = ServerController.GetDomains(packageId);
// Get hostheader
foreach (ServerBinding b in web.GetSiteBindings(siteItem.SiteId))
{
if ((!DoesHeaderExistInDomains(b.Host.ToLower(), domains)) && (!string.IsNullOrEmpty(b.Host)))
{
// If not get domain info and add to domains
int domainId = FindDomainForHeader(b.Host.ToLower(), domains);
if (domainId > 0)
{
DomainInfo domain = ServerController.GetDomain(domainId);
DomainInfo newDomain = new DomainInfo();
newDomain.DomainName = b.Host.ToLower();
newDomain.PackageId = domain.PackageId;
newDomain.IsDomainPointer = true;
int newDomainID = ServerController.AddDomain(newDomain, domain.IsInstantAlias, false);
if (newDomainID > 0)
{
newDomain = ServerController.GetDomain(newDomainID);
if (newDomain != null)
{
newDomain.WebSiteId = siteId;
newDomain.ZoneItemId = domain.ZoneItemId;
newDomain.DomainItemId = domain.DomainId;
ServerController.UpdateDomain(newDomain);
}
}
}
}
}
return 0;
}
示例4: AddWebSitePointer
//.........这里部分代码省略.........
try
{
DNSServer dns = new DNSServer();
ServiceProviderProxy.Init(dns, zone.ServiceId);
DnsRecord[] domainRecords = dns.GetZoneRecords(zone.Name);
var duplicateRecords = (from zoneRecord in domainRecords
from resRecord in resourceRecords
where zoneRecord.RecordName == resRecord.RecordName
where zoneRecord.RecordType == resRecord.RecordType
select zoneRecord).ToArray();
if (duplicateRecords != null && duplicateRecords.Count() > 0)
{
dns.DeleteZoneRecords(zone.Name, duplicateRecords);
}
// add new resource records
dns.AddZoneRecords(zone.Name, resourceRecords.ToArray());
}
catch (Exception ex1)
{
TaskManager.WriteError(ex1, "Error updating DNS records");
}
}
// update host headers
List<ServerBinding> bindings = new List<ServerBinding>();
// get existing web site bindings
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
// check if web site has dedicated IP assigned
bool dedicatedIp = bindings.Exists(binding => { return String.IsNullOrEmpty(binding.Host) && binding.IP != "*"; });
// update binding only for "shared" ip addresses
// add new host headers
string ipAddr = "*";
if (ip != null)
ipAddr = !String.IsNullOrEmpty(ip.InternalIP) ? ip.InternalIP : ip.ExternalIP;
// fill bindings
FillWebServerBindings(bindings, dnsRecords, ipAddr, hostName, domain.DomainName, ignoreGlobalDNSRecords);
//for logging purposes
foreach (ServerBinding b in bindings)
{
string header = string.Format("{0} {1} {2}", b.Host, b.IP, b.Port);
TaskManager.WriteParameter("Add Binding", header);
}
// update bindings
if (updateWebSite)
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray(), false);
// update domain
if (!rebuild)
{
domain.WebSiteId = siteItemId;
domain.IsDomainPointer = true;
foreach (ServerBinding b in bindings)
{
//add new domain record
示例5: DeleteWebSitePointer
public static int DeleteWebSitePointer(int siteItemId, int domainId, bool updateWebSite)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// load site item
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
if (siteItem == null)
return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;
// load domain item
DomainInfo domain = ServerController.GetDomain(domainId);
if (domain == null)
return BusinessErrorCodes.ERROR_DOMAIN_PACKAGE_ITEM_NOT_FOUND;
// load appropriate zone
DnsZone zone = (DnsZone)PackageController.GetPackageItem(domain.ZoneItemId);
//if (zone == null)
// return BusinessErrorCodes.ERROR_DNS_PACKAGE_ITEM_NOT_FOUND;
// get zone records for the service
List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(siteItem.ServiceId);
// change DNS zone
IPAddressInfo ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
if (ip == null)
return BusinessErrorCodes.ERROR_WEB_SITE_IP_ADDRESS_NOT_SPECIFIED;
List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(
dnsRecords, domain.DomainName, ip.ExternalIP);
// place log record
TaskManager.StartTask("WEB_SITE", "DELETE_POINTER", siteItem.Name);
TaskManager.ItemId = siteItemId;
TaskManager.WriteParameter("Domain pointer", domain.DomainName);
try
{
if (zone != null)
{
try
{
DNSServer dns = new DNSServer();
ServiceProviderProxy.Init(dns, zone.ServiceId);
dns.DeleteZoneRecords(zone.Name, resourceRecords.ToArray());
}
catch(Exception ex1)
{
TaskManager.WriteError(ex1, "Error deleting DNS records");
}
}
// load web settings
StringDictionary webSettings = ServerController.GetServiceSettings(siteItem.ServiceId);
int sharedIpId = Utils.ParseInt(webSettings["SharedIP"], 0);
bool dedicatedIp = (siteItem.SiteIPAddressId != sharedIpId);
if (updateWebSite && !dedicatedIp)
{
// update host headers
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
List<ServerBinding> bindings = new List<ServerBinding>();
bindings.AddRange(web.GetSiteBindings(siteItem.SiteId));
// remove host headers
List<ServerBinding> domainBindings = new List<ServerBinding>();
FillWebServerBindings(domainBindings, dnsRecords, "", domain.DomainName);
// fill to remove list
List<string> headersToRemove = new List<string>();
foreach (ServerBinding domainBinding in domainBindings)
{
headersToRemove.Add(domainBinding.Host);
}
int pos = 0;
while (pos < bindings.Count)
{
if (headersToRemove.Contains(bindings[pos].Host))
{
bindings.RemoveAt(pos);
continue;
}
else
{
pos++;
}
}
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
}
// update domain
domain.WebSiteId = 0;
ServerController.UpdateDomain(domain);
//.........这里部分代码省略.........
示例6: AddWebSitePointer
internal static int AddWebSitePointer(int siteItemId, int domainId, bool updateWebSite)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// load site item
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
if (siteItem == null)
return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;
// load domain item
DomainInfo domain = ServerController.GetDomain(domainId);
if (domain == null)
return BusinessErrorCodes.ERROR_DOMAIN_PACKAGE_ITEM_NOT_FOUND;
// load appropriate zone
DnsZone zone = (DnsZone)PackageController.GetPackageItem(domain.ZoneItemId);
//if (zone == null)
// return BusinessErrorCodes.ERROR_DNS_PACKAGE_ITEM_NOT_FOUND;
// get zone records for the service
List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(siteItem.ServiceId);
// change DNS zone
IPAddressInfo ip = ServerController.GetIPAddress(siteItem.SiteIPAddressId);
if (ip == null)
return BusinessErrorCodes.ERROR_WEB_SITE_IP_ADDRESS_NOT_SPECIFIED;
List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(
dnsRecords, domain.DomainName, ip.ExternalIP);
// place log record
TaskManager.StartTask("WEB_SITE", "ADD_POINTER", siteItem.Name);
TaskManager.ItemId = siteItemId;
TaskManager.WriteParameter("Domain pointer", domain.DomainName);
try
{
if (zone != null)
{
try
{
DNSServer dns = new DNSServer();
ServiceProviderProxy.Init(dns, zone.ServiceId);
// add new resource records
dns.AddZoneRecords(zone.Name, resourceRecords.ToArray());
}
catch(Exception ex1)
{
TaskManager.WriteError(ex1, "Error updating DNS records");
}
}
// update host headers
if (updateWebSite)
{
// load web settings
StringDictionary webSettings = ServerController.GetServiceSettings(siteItem.ServiceId);
int sharedIpId = Utils.ParseInt(webSettings["SharedIP"], 0);
bool dedicatedIp = (siteItem.SiteIPAddressId != sharedIpId);
if (!dedicatedIp)
{
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
List<ServerBinding> bindings = new List<ServerBinding>();
ServerBinding[] siteBindings = web.GetSiteBindings(siteItem.SiteId);
if(siteBindings != null)
bindings.AddRange(siteBindings);
// add new host headers
string ipAddr = ip.InternalIP;
if (ipAddr == null || ipAddr == "")
ipAddr = ip.ExternalIP;
// fill bindings
FillWebServerBindings(bindings, dnsRecords, ipAddr, domain.DomainName);
// update bindings
web.UpdateSiteBindings(siteItem.SiteId, bindings.ToArray());
}
}
// update domain
domain.WebSiteId = siteItemId;
ServerController.UpdateDomain(domain);
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
//.........这里部分代码省略.........