本文整理汇总了C#中Microsoft.Web.Administration.ServerManager类的典型用法代码示例。如果您正苦于以下问题:C# ServerManager类的具体用法?C# ServerManager怎么用?C# ServerManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerManager类属于Microsoft.Web.Administration命名空间,在下文中一共展示了ServerManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public void Validate(string webSiteName, string hostName, string portNumber)
{
if (string.IsNullOrEmpty(webSiteName))
throw new ArgumentNullException("webSiteName");
ValidateHostName(hostName);
ValidatePortNumber(portNumber);
using (var serverManager = new ServerManager())
{
int portNumberValue = Convert.ToInt32(portNumber);
foreach (var site in serverManager.Sites.Where(s => !string.Equals(s.Name, webSiteName, StringComparison.Ordinal) && s.State == ObjectState.Started))
{
foreach (var binding in site.Bindings.Where(i => i.Protocol.Equals("http") || i.Protocol.Equals("https")))
{
if (binding.EndPoint.Port != portNumberValue)
continue;
if (string.IsNullOrEmpty(hostName) && string.IsNullOrEmpty(binding.Host))
{
throw new Exception(string.Format("The specified port number '{0}' already used by '{1}' site.", binding.EndPoint.Port, site.Name));
}
else if (string.Equals(binding.Host, hostName, StringComparison.Ordinal))
{
throw new Exception(string.Format("The specified host name '{0}' and port Number '{1}' already used by '{2}' site.", binding.Host, binding.EndPoint.Port, site.Name));
}
}
}
}
}
示例2: DoProcessing
protected override void DoProcessing()
{
using (ServerManager serverManager = new ServerManager())
{
ServerManagerWrapper serverManagerWrapper = new ServerManagerWrapper(serverManager, this.SiteName, this.VirtualPath);
PHPConfigHelper configHelper = new PHPConfigHelper(serverManagerWrapper);
PHPIniFile phpIniFile = configHelper.GetPHPIniFile();
PHPIniSetting setting = Helper.FindSetting(phpIniFile.Settings, Name);
if (setting == null)
{
if (ShouldProcess(Name))
{
RemoteObjectCollection<PHPIniSetting> settings = new RemoteObjectCollection<PHPIniSetting>();
settings.Add(new PHPIniSetting(Name, Value, Section));
configHelper.AddOrUpdatePHPIniSettings(settings);
}
}
else
{
ArgumentException ex = new ArgumentException(String.Format(Resources.SettingAlreadyExistsError, Name));
ReportNonTerminatingError(ex, "InvalidArgument", ErrorCategory.InvalidArgument);
}
}
}
示例3: AddWebSite
public bool AddWebSite(string username, string password, string fqdn, string homeDirectory,
string bindingProtocol, string bindingInformation)
{
using (var serverManager = new ServerManager())
{
var pool = serverManager.ApplicationPools.Add(ReverseFqdn(fqdn));
pool.ManagedRuntimeVersion = "v4.0";
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
{
pool.ProcessModel.IdentityType = ProcessModelIdentityType.ApplicationPoolIdentity;
}
else
{
pool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
pool.ProcessModel.UserName = username;
pool.ProcessModel.Password = password;
}
var site = serverManager.Sites.Add(ReverseFqdn(fqdn), bindingProtocol, bindingInformation, homeDirectory);
var app = site.Applications.FirstOrDefault();
app.ApplicationPoolName = pool.Name;
serverManager.CommitChanges();
}
AddIndexFile(homeDirectory, fqdn);
return true;
}
示例4: DoProcessing
protected override void DoProcessing()
{
using (var serverManager = new ServerManager())
{
var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
var configHelper = new PHPConfigHelper(serverManagerWrapper);
var phpIniFile = configHelper.GetPHPIniFile();
WildcardPattern wildcard = PrepareWildcardPattern(Name);
foreach (var extension in phpIniFile.Extensions)
{
if (!wildcard.IsMatch(extension.Name))
{
continue;
}
if (Status == PHPExtensionStatus.Disabled && extension.Enabled)
{
continue;
}
if (Status == PHPExtensionStatus.Enabled && !extension.Enabled)
{
continue;
}
var extensionItem = new PHPExtensionItem(extension);
WriteObject(extensionItem);
}
}
}
示例5: CreateSite
public static void CreateSite(SiteDTO siteDto)
{
var mgr = new ServerManager();
var sites = mgr.Sites;
CreateSiteInIIS(sites, siteDto);
mgr.CommitChanges();
}
示例6: OnStart
public override bool OnStart()
{
try
{
using (var server = new ServerManager())
{
const string site = "Web";
var siteName = string.Format("{0}_{1}", RoleEnvironment.CurrentRoleInstance.Id, site);
var config = server.GetApplicationHostConfiguration();
ConfigureAccessSection(config, siteName);
var iisClientCertificateMappingAuthenticationSection = EnableIisClientCertificateMappingAuthentication(config, siteName);
ConfigureManyToOneMappings(iisClientCertificateMappingAuthenticationSection);
ConfigureOneToOneMappings(iisClientCertificateMappingAuthenticationSection);
server.CommitChanges();
}
}
catch (Exception e)
{
Debug.WriteLine(e);
// handle error here
}
return base.OnStart();
}
示例7: GetAppPoolForApp
public static ApplicationPool GetAppPoolForApp(string serviceInstancePath)
{
using (ServerManager serverManager = new ServerManager())
{
return GetAppPoolForApp(serverManager, serviceInstancePath);
}
}
示例8: Build
public override void Build(IBounce bounce)
{
var iisServer = new ServerManager();
var existingSite = iisServer.Sites[Name.Value];
if (!SiteUpToDate(existingSite)) {
bounce.Log.Info("installing IIS website at: " + Directory.Value);
RemoveWebSiteIfExtant(iisServer);
var site = iisServer.Sites.Add(Name.Value, Directory.Value, Port.Value);
if (Bindings != null && Bindings.Value != null) {
site.Bindings.Clear();
foreach (var binding in Bindings.Value) {
site.Bindings.Add(binding.Information.Value, binding.Protocol.Value);
}
}
if (ApplicationPoolNameIfSet != null) {
site.ApplicationDefaults.ApplicationPoolName = ApplicationPoolNameIfSet;
}
iisServer.CommitChanges();
} else {
bounce.Log.Info("IIS website already installed");
}
}
示例9: Execute
/// <summary>
/// Executes this instance.
/// </summary>
/// <returns>A value indicating whether the task completed successfully.</returns>
public override bool Execute()
{
var serverManager = new ServerManager();
// Find the root web site that this web application will be created under.
var site = serverManager.Sites.FirstOrDefault(s => string.Equals(s.Name, this.WebSiteName, StringComparison.OrdinalIgnoreCase));
if (site == null) {
Log.LogMessage(MessageImportance.Low, TaskStrings.NoMatchingWebSiteFound, this.WebSiteName);
return true;
}
if (this.VirtualPaths.Length == 0) {
// Nothing to do.
return true;
}
foreach (ITaskItem path in this.VirtualPaths) {
var app = site.Applications.FirstOrDefault(a => string.Equals(a.Path, path.ItemSpec, StringComparison.OrdinalIgnoreCase));
if (app != null) {
site.Applications.Remove(app);
Log.LogMessage(MessageImportance.Normal, TaskStrings.DeletedWebApplication, app.Path);
} else {
Log.LogMessage(MessageImportance.Low, TaskStrings.WebApplicationNotFoundSoNotDeleted, path.ItemSpec);
}
}
serverManager.CommitChanges();
return true;
}
示例10: RewriteStem
private void RewriteStem(ServerManager server, string serviceStem)
{
// Get the site config
const string siteBaseName = "Web"; // From the CSDEF file
string siteName =
RoleEnvironment.CurrentRoleInstance.Id + "_" + siteBaseName;
var config = server.Sites[siteName].GetWebConfiguration();
var rewriteSection = config.GetSection("system.webServer/rewrite");
if (rewriteSection == null)
{
var rewriteRules = rewriteSection.GetChildElement("rules");
if (rewriteRules != null)
{
foreach (var rewriteRule in rewriteRules.ChildElements)
{
var action = rewriteRules.GetChildElement("action");
if (action != null)
{
string url = action.GetAttributeValue("url");
string rewritten = url.Replace("nuget.org", serviceStem);
if (!String.Equals(url, rewritten, StringComparison.Ordinal))
{
action.SetAttributeValue("url", rewritten);
}
}
}
}
}
}
示例11: GetStatus
public ApplicationInstanceStatus GetStatus(string applicationInstanceName)
{
ApplicationInstanceStatus rv = ApplicationInstanceStatus.Unknown;
try
{
using (var manager = new ServerManager())
{
ApplicationPool applicationPool = GetApplicationPool(manager, applicationInstanceName);
Site applicationSite = GetSite(manager, applicationInstanceName);
if (applicationSite.State == ObjectState.Stopped || applicationPool.State == ObjectState.Stopped)
{
rv = ApplicationInstanceStatus.Stopped;
}
else if (applicationSite.State == ObjectState.Stopping || applicationPool.State == ObjectState.Stopping)
{
rv = ApplicationInstanceStatus.Stopping;
}
else if (applicationSite.State == ObjectState.Starting || applicationPool.State == ObjectState.Starting)
{
rv = ApplicationInstanceStatus.Starting;
}
else if (applicationSite.State == ObjectState.Started || applicationPool.State == ObjectState.Started)
{
rv = ApplicationInstanceStatus.Started;
}
}
}
catch (Exception ex)
{
log.Error(ex);
}
return rv;
}
示例12: OnStart
public override bool OnStart()
{
try
{
Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
Trace.TraceInformation("Starting Gateway");
// Enable IIS Reverse Proxy
using (ServerManager server = new ServerManager())
{
var proxySection = server.GetApplicationHostConfiguration().GetSection("system.webServer/proxy");
proxySection.SetAttributeValue("enabled", true);
server.CommitChanges();
Trace.TraceInformation("Enabled Reverse Proxy");
// Patch web.config rewrite rules
string serviceStem = RoleEnvironment.GetConfigurationSettingValue("Gateway.ServiceStem");
if (!String.Equals(serviceStem, "nuget.org", StringComparison.OrdinalIgnoreCase))
{
RewriteStem(server, serviceStem);
}
server.CommitChanges();
}
return base.OnStart();
}
catch (Exception ex)
{
Trace.TraceError("Error starting gateway: {0}", ex.ToString());
throw;
}
}
示例13: StopAppPool
/// <summary>
/// Stops an AppPool on the local system.
/// </summary>
/// <param name="name">Name of the AppPool to stop.</param>
public override void StopAppPool(string name)
{
using (var manager = new ServerManager())
{
var pool = manager.ApplicationPools[name];
if (pool == null)
throw new IISException("Application pool not found.", MessageLevel.Warning);
try
{
pool.Stop();
}
catch (COMException ex)
{
if ((uint) ex.ErrorCode == 0x80070426)
throw new IISException("Application pool is already stopped.", ex, MessageLevel.Information);
else
throw new IISException("Could not stop application pool: " + ex.Message);
}
catch (Exception ex)
{
throw new IISException("Could not stop application pool: " + ex.Message);
}
}
}
示例14: PurgeAllSites
public static void PurgeAllSites()
{
using (var serverManager = new ServerManager())
{
var applications = serverManager.ApplicationPools.ToList();
if (!applications.Any())
{
// There is nothing to do.
return;
}
foreach (var appPool in applications)
{
appPool.Stop();
// Find all site & applications using this pool.
var sites = serverManager.Sites
.Where(site => site.Applications.Any(x => x.ApplicationPoolName == appPool.Name)).ToList();
foreach (var site in sites)
{
serverManager.Sites[site.Name].Stop();
serverManager.Sites.Remove(site);
}
serverManager.ApplicationPools.Remove(appPool);
}
serverManager.CommitChanges();
}
}
示例15: AddSite
public static void AddSite(string siteName, string hostName = null)
{
using (var sm = new ServerManager())
{
var invalidChars = SiteCollection.InvalidSiteNameCharacters();
if (siteName.IndexOfAny(invalidChars) > -1)
{
throw new Exception("Invalid Site Name: {0}".Fmt(siteName));
}
var appPool = AddAppPool(sm, siteName, "v4.0", ManagedPipelineMode.Integrated);
if (sm.Sites[siteName] != null)
{
return;
}
string path = "C:\\inetpub\\wwwroot\\{0}".Fmt(siteName);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
// Set HostName info for binding
var site = hostName != null ? sm.Sites.Add(siteName, "http", "*:80:{0}".Fmt(hostName), path) : sm.Sites.Add(siteName, path, 80);
site.ServerAutoStart = true;
site.ApplicationDefaults.ApplicationPoolName = appPool.Name;
sm.CommitChanges();
AddMsDeployAccessToSite(sm, siteName, "CISetupWizard");
}
}