简体   繁体   中英

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)
        {
        }
    }
}

Use any ofCurrentCultureIgnoreCase or InvariantCultureIgnoreCase or OrdinalIgnoreCase , whichever suits your needs, for example:

q => q.Name.Equals("FLOWS", StringComparison.CurrentCultureIgnoreCase)

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. eg

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();
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM