'check the site name hosted on IIS using code
My site name is "Flows" on IIS if i search with the name "FLOWS" its not working so is it possible that i can search it without case sensitive.
class Program
{
static void Main(string[] args)
{
try
{
using (ServerManager manager = new ServerManager())
{
var iisManager = ServerManager.OpenRemote("ServerName");
Microsoft.Web.Administration.Site site = iisManager.Sites.Where(q => q.Name.("Flows")).FirstOrDefault();
if (site.State == site.Start())
{
site.Stop();
}
else
{
site.Start();
}
}
}
catch (Exception ex)
{
}
}
}
Solution 1:[1]
Use any of CurrentCultureIgnoreCase or InvariantCultureIgnoreCase or OrdinalIgnoreCase, whichever suits your needs, for example:
q => q.Name.Equals("FLOWS", StringComparison.CurrentCultureIgnoreCase)
Solution 2:[2]
Case insensitivity can be enabled for string comparisons by setting the case rules using a StringComparison enum value.
Passing any of CurrentCultureIgnoreCase
, InvariantCultureIgnoreCase
, or OrdinalIgnoreCase
to the comparison will result in case insensitive comparison. e.g.
class Program
{
static void Main(string[] args)
{
using (ServerManager manager = new ServerManager())
{
var iisManager = ServerManager.OpenRemote("ServerName");
Microsoft.Web.Administration.Site site = iisManager.Sites.Where(
q => q.Name.Equals("FLOWS", StringComparison.CurrentCultureIgnoreCase)
)
if (site.State == site.Start())
{
site.Stop();
}
else
{
site.Start();
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dante May Code |
Solution 2 | KMR |