[英]ServerManager iis check default site wasnt change c#
I need to overwritte Default Site if isnt use, overwrite it if the user decides so or create a new one.如果不使用,我需要覆盖默认站点,如果用户决定覆盖它或创建一个新站点。
I am trying check all sites, and take this with port 80 and name "Default Web Site".我正在尝试检查所有站点,并使用端口 80 并将其命名为“默认 Web 站点”。 Next if it exist I want to take physical path and check does it equal the default path and contains all files for default path.
接下来,如果它存在,我想采用物理路径并检查它是否等于默认路径并包含默认路径的所有文件。 In this way:
这样:
private static void CheckSite(SiteCollection applicationSites)
{
int i = 0;
foreach (var item in applicationSites)
{
foreach (var binding in item.Bindings)
{
int port;
if (binding.EndPoint != null)
port = binding.EndPoint.Port;
else
continue;
if (port == 80 && item.Name == "Default Web Site")
{
var path = item.Applications[i].VirtualDirectories[0].PhysicalPath;
string[] dire = Directory.GetFiles(path);
}
}
i++;
}
}
Is there better way to do this?有没有更好的方法来做到这一点? I am using Microsoft.Web.Administration.
我正在使用 Microsoft.Web.Administration。
You can get the Default Web Site as below code:您可以通过以下代码获取默认 Web 站点:
using (ServerManager serverManager = new ServerManager())
{
var sites = serverManager.Sites;
foreach (Site site in sites)
{
var sitename = site.Name;
if (sitename == "Default Web Site")
{
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.