本文整理汇总了C#中Microsoft.Web.Administration.ServerManager类的典型用法代码示例。如果您正苦于以下问题:C# ServerManager类的具体用法?C# ServerManager怎么用?C# ServerManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerManager类属于Microsoft.Web.Administration命名空间,在下文中一共展示了ServerManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
}
}
}
}
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:31,代码来源:SiteBindingValidator.cs
示例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);
}
}
}
开发者ID:modulexcite,项目名称:PHPManager,代码行数:25,代码来源:NewPHPSettingCmdlet.cs
示例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;
}
开发者ID:bisand,项目名称:IISAdmin,代码行数:28,代码来源:IisServer.cs
示例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);
}
}
}
开发者ID:modulexcite,项目名称:PHPManager,代码行数:31,代码来源:GetPHPExtensionCmdlet.cs
示例5: CreateSite
public static void CreateSite(SiteDTO siteDto)
{
var mgr = new ServerManager();
var sites = mgr.Sites;
CreateSiteInIIS(sites, siteDto);
mgr.CommitChanges();
}
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:7,代码来源:IISHelper.cs
示例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();
}
开发者ID:showlowtech,项目名称:AzureWithCertificatesSample,代码行数:27,代码来源:WebRole.cs
示例7: GetAppPoolForApp
public static ApplicationPool GetAppPoolForApp(string serviceInstancePath)
{
using (ServerManager serverManager = new ServerManager())
{
return GetAppPoolForApp(serverManager, serviceInstancePath);
}
}
开发者ID:rickeygalloway,项目名称:Test,代码行数:7,代码来源:IISUtilities.cs
示例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");
}
}
开发者ID:nbucket,项目名称:bounce,代码行数:26,代码来源:Iis7WebSite.cs
示例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;
}
开发者ID:jcp-xx,项目名称:dotnetopenid,代码行数:34,代码来源:DeleteWebApplication.cs
示例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);
}
}
}
}
}
}
开发者ID:NuGet,项目名称:NuGet.Services.Gateway,代码行数:30,代码来源:WebRole.cs
示例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;
}
开发者ID:SinghJPS,项目名称:ironfoundry,代码行数:35,代码来源:WebServerAdministrationProvider.cs
示例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;
}
}
开发者ID:NuGet,项目名称:NuGet.Services.Gateway,代码行数:32,代码来源:WebRole.cs
示例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);
}
}
}
开发者ID:LogikBlitz,项目名称:bmx-windows,代码行数:29,代码来源:IIS7Util.cs
示例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();
}
}
开发者ID:Applicita,项目名称:AzureWebFarm.OctopusDeploy,代码行数:35,代码来源:IisEnvironment.cs
示例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");
}
}
开发者ID:ServiceStack,项目名称:CISetupWizard,代码行数:30,代码来源:IisHelper.cs
示例16: DeployApp
private static void DeployApp(DeployCommandOptions deployCommandOptions)
{
var iisManager = new ServerManager();
const string name = "speedymailer.app";
var exists = iisManager.Sites.Any(x => x.Name == name);
var appPreReleasePath = Path.Combine(deployCommandOptions.BaseDirectory, "Release", "App");
var appPath = Path.Combine(deployCommandOptions.BaseDirectory, "App");
if (exists)
{
var site = iisManager.Sites[name];
site.Stop();
iisManager.CommitChanges();
DeleteAppFolder(appPath, appPreReleasePath);
site.Start();
iisManager.CommitChanges();
}
else
{
DeleteAppFolder(appPath, appPreReleasePath);
iisManager.Sites.Add(name, "http", string.Format("*:80:app.{0}", deployCommandOptions.BaseUrl), appPath);
var site = iisManager.Sites[name];
iisManager.CommitChanges();
}
}
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:31,代码来源:Program.cs
示例17: 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();
var nameWildcard = PrepareWildcardPattern(Name);
var sectionWildcard = PrepareWildcardPattern(Section);
foreach (var setting in phpIniFile.Settings)
{
if (!nameWildcard.IsMatch(setting.Name))
{
continue;
}
if (!sectionWildcard.IsMatch(setting.Section))
{
continue;
}
var settingItem = new PHPSettingItem(setting);
WriteObject(settingItem);
}
}
}
开发者ID:modulexcite,项目名称:PHPManager,代码行数:27,代码来源:GetPHPSettingCmdlet.cs
示例18: iis7_create_site
public static void iis7_create_site(string siteName, string applicationPoolName, string path, int port)
{
if (string.IsNullOrEmpty(siteName))
throw new StringIsNullOrEmptyException("siteName");
if (string.IsNullOrEmpty(applicationPoolName))
throw new StringIsNullOrEmptyException("applicationPoolName");
if (string.IsNullOrEmpty(path))
throw new StringIsNullOrEmptyException("path");
using (var iisManager = new ServerManager())
{
if (iisManager.Sites[siteName] != null)
throw new SiteAlreadyExistsException(siteName);
iisManager.Sites.Add(siteName, new DirectoryInfo(path.Replace('\\', '/')).FullName, port);
ApplicationPool applicationPool = iisManager.ApplicationPools[applicationPoolName];
if (applicationPool == null)
iisManager.ApplicationPools.Add(applicationPoolName);
iisManager.Sites[siteName].Applications[0].ApplicationPoolName = applicationPoolName;
iisManager.CommitChanges();
}
}
开发者ID:creamdog,项目名称:PhantomContrib,代码行数:26,代码来源:IIS7Administraion.cs
示例19: IisWebSite
/// <summary>
/// Initializes a new instance of the <see cref="IisWebSite"/> class.
/// </summary>
/// <param name="siteName">
/// The site Name.
/// </param>
/// <param name="sitePhysicalPath">
/// The site Physical Path.
/// </param>
/// <param name="sitePort">
/// The site Port.
/// </param>
/// <param name="pool">
/// The pool.
/// </param>
public IisWebSite(string siteName, string sitePhysicalPath, int sitePort, IisApplicationPool pool)
{
try
{
this.serverManager = new ServerManager();
string relativePath = Path.Combine(Environment.CurrentDirectory, sitePhysicalPath);
string absolutePath = Path.GetFullPath(relativePath);
this.Port = sitePort;
this.Name = siteName;
if (this.serverManager.Sites[siteName] != null)
{
// if site exists we need to remove it because it may contain wrong physical path.
this.Remove();
}
this.site = this.serverManager.Sites.Add(siteName, absolutePath, sitePort);
this.site.ServerAutoStart = true;
this.site.Applications[0].ApplicationPoolName = pool.Name;
this.currentPool = pool;
this.serverManager.CommitChanges();
Trace.TraceInformation(
"IISWebSite {0} deployed successfully.", siteName);
}
catch (Exception ex)
{
Trace.TraceError("Exception occured while deploying IIS Website: {0}. The exception thrown was {1}", siteName, ex.Message);
throw;
}
}
开发者ID:Microsoft,项目名称:ApplicationInsights-dotnet-server,代码行数:48,代码来源:IisWebSite.cs
示例20: RemoveWebSiteIfExtant
private void RemoveWebSiteIfExtant(ServerManager server)
{
var site = server.Sites[Name.Value];
if (site != null) {
server.Sites.Remove(site);
}
}
开发者ID:jimbutler,项目名称:bounce,代码行数:7,代码来源:Iis7WebSite.cs
注:本文中的Microsoft.Web.Administration.ServerManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论