本文整理汇总了C#中WebsitePanel.Providers.Web.WebServer.UpdateSiteBindings方法的典型用法代码示例。如果您正苦于以下问题:C# WebServer.UpdateSiteBindings方法的具体用法?C# WebServer.UpdateSiteBindings怎么用?C# WebServer.UpdateSiteBindings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebsitePanel.Providers.Web.WebServer
的用法示例。
在下文中一共展示了WebServer.UpdateSiteBindings方法的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: SwitchWebSiteToSharedIP
public static int SwitchWebSiteToSharedIP(int siteItemId)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// load web site item
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
if (siteItem == null)
return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;
// place log record
TaskManager.StartTask("WEB_SITE", "SWITCH_TO_SHARED_IP", siteItem.Name, siteItemId);
try
{
IPAddressInfo ip;
DomainInfo domain = ServerController.GetDomain(siteItem.Name);
DomainInfo ZoneInfo = ServerController.GetDomain(domain.DomainItemId);
if (ZoneInfo == null)
throw new Exception("Parent zone not found");
if (ZoneInfo.ZoneItemId > 0)
{
StringDictionary settings = ServerController.GetServiceSettings(siteItem.ServiceId);
if (string.IsNullOrEmpty(settings["PublicSharedIP"]))
return BusinessErrorCodes.ERROR_PUBLICSHAREDIP_FOR_SHAREDIP;
}
//cleanup certificates
List<SSLCertificate> certificates = GetCertificatesForSite(siteItemId);
foreach (SSLCertificate c in certificates)
{
DeleteCertificate(siteItemId, c);
}
certificates = GetPendingCertificates(siteItemId);
foreach (SSLCertificate c in certificates)
{
DeleteCertificateRequest(siteItemId, c.id);
}
// remove all web site pointers
List<DomainInfo> pointers = GetWebSitePointers(siteItemId);
foreach (DomainInfo pointer in pointers)
DeleteWebSitePointer(siteItemId, pointer.DomainId, true, true, false);
// remove web site main pointer
if (domain != null)
DeleteWebSitePointer(siteItemId, domain.DomainId, true, true, false);
// clear binding left overs
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
List<ServerBinding> newBindings = new List<ServerBinding>();
try
{
web.UpdateSiteBindings(siteItem.SiteId, newBindings.ToArray(), true);
}
catch (Exception)
{
}
List<WebSite> sites = WebServerController.GetWebSites(domain.PackageId, false);
bool oneSiteOnly = (sites.Count == 1);
if (oneSiteOnly)
{
// 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.RemoveServiceDNSRecords(domain.PackageId, ResourceGroups.Web, domain, serviceIp, true);
}
//figure out the PackageAddressId
PackageIPAddress packageIpAddress = null;
var siteIpAddresses = ServerController.GetItemIPAddresses(siteItemId, IPAddressPool.None);
foreach (var siteIp in siteIpAddresses)
{
packageIpAddress = ServerController.GetPackageIPAddress(siteIp.AddressID);
if (packageIpAddress != null && packageIpAddress.AddressID == siteItem.SiteIPAddressId)
//.........这里部分代码省略.........
示例3: SwitchWebSiteToDedicatedIP
public static int SwitchWebSiteToDedicatedIP(int siteItemId, int ipAddressId)
{
// check account
int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
if (accountCheck < 0) return accountCheck;
// load web site item
WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
if (siteItem == null)
return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;
int addressId = 0;
PackageIPAddress packageIp = ServerController.GetPackageIPAddress(ipAddressId);
if (packageIp != null)
{
addressId = packageIp.AddressID;
}
List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(siteItem.ServiceId);
foreach (GlobalDnsRecord d in dnsRecords)
{
if (!string.IsNullOrEmpty(d.ExternalIP))
{
if (!IsValidIPAdddress(d.ExternalIP)) return BusinessErrorCodes.ERROR_GLOBALDNS_FOR_DEDICATEDIP;
}
}
// place log record
TaskManager.StartTask("WEB_SITE", "SWITCH_TO_DEDICATED_IP", siteItem.Name, siteItemId);
try
{
IPAddressInfo ip;
// remove all web site pointers
DomainInfo domain = ServerController.GetDomain(siteItem.Name);
DomainInfo ZoneInfo = ServerController.GetDomain(domain.DomainItemId);
if (ZoneInfo == null)
throw new Exception("Parent zone not found");
//cleanup certificates
List<SSLCertificate> certificates = GetCertificatesForSite(siteItemId);
foreach (SSLCertificate c in certificates)
{
DeleteCertificate(siteItemId, c);
}
certificates = GetPendingCertificates(siteItemId);
foreach (SSLCertificate c in certificates)
{
DeleteCertificateRequest(siteItemId, c.id);
}
List<DomainInfo> pointers = GetWebSitePointers(siteItemId);
foreach (DomainInfo pointer in pointers)
DeleteWebSitePointer(siteItemId, pointer.DomainId, true, true, false);
// remove web site main pointer
if (domain != null)
DeleteWebSitePointer(siteItemId, domain.DomainId, true, true, false);
// clear binding left overs
List<ServerBinding> newBindings = new List<ServerBinding>();
WebServer web = new WebServer();
ServiceProviderProxy.Init(web, siteItem.ServiceId);
try
{
web.UpdateSiteBindings(siteItem.SiteId, newBindings.ToArray(), true);
}
catch (Exception)
{
}
List<WebSite> sites = WebServerController.GetWebSites(domain.PackageId, false);
bool oneSiteOnly = (sites.Count == 1);
if (oneSiteOnly)
{
// 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.RemoveServiceDNSRecords(domain.PackageId, ResourceGroups.Web, domain, serviceIp, true);
}
// update site item
siteItem.SiteIPAddressId = addressId;
//.........这里部分代码省略.........
示例4: AddWebSitePointer
//.........这里部分代码省略.........
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
if (!string.IsNullOrEmpty(b.Host))
{
domain.DomainName = b.Host;
DomainInfo domainTmp = ServerController.GetDomain(domain.DomainName);
if (!((domainTmp != null) && (domainTmp.WebSiteId == siteItemId)))
{
int domainID = ServerController.AddDomain(domain, domain.IsInstantAlias, false);
domainTmp = ServerController.GetDomain(domainID);
if (domainTmp != null)
{
domainTmp.WebSiteId = siteItemId;
domainTmp.ZoneItemId = domain.ZoneItemId;
domainTmp.DomainItemId = domainId;
ServerController.UpdateDomain(domainTmp);
}
}
}
}
}
else
{
if (domain.ZoneItemId > 0)
{
DomainInfo domainTmp = ServerController.GetDomain(string.IsNullOrEmpty(hostName) ? domain.DomainName : hostName + "." + domain.DomainName, true, true);
if (domainTmp != null)
{
domainTmp.ZoneItemId = domain.ZoneItemId;
ServerController.UpdateDomain(domainTmp);
}
}
}
return 0;
}
catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
finally
{
TaskManager.CompleteTask();
}
}
示例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
{
//.........这里部分代码省略.........