1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/// <summary>
/// Get website id on <paramref name="websiteName"/>
/// </summary>
/// <param name = "websiteName">Name of the website e.g. test</param>
/// <returns>
/// Less the 0, site does not exist
/// Id of the existing site
/// </returns>
public long GetWebSiteId(string websiteName)
{
long result = -1;
using (var w3svc = new DirectoryEntry("IIS://localhost/w3svc"))
{
w3svc.RefreshCache();
foreach (DirectoryEntry site in w3svc.Children)
{
using (site)
{
site.RefreshCache();
if (site.Properties["ServerComment"] != null && site.Properties["ServerComment"].Value != null)
{
if (site.Properties["ServerComment"].Value.ToString().Equals(websiteName, StringComparison.OrdinalIgnoreCase))
long.TryParse(site.Name, out result);
}
}
}
}
return result;
}
|