Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a website it starts the iis website and it is running fine when i use vs2010 and when i use the same code in vs2012 project it is throwing an expection which i have provided.
protected void Button2_Click(object sender, EventArgs e)
        {
            var server = new ServerManager();
            var site = server.Sites.FirstOrDefault(s => s.Name == "chinna");
            if (site != null)
            {
                //stop the site...
                site.Stop();
                if (site.State == ObjectState.Stopped)
                {
                    Button1.Text = "website stopped";
                }
                else
                {
                    throw new InvalidOperationException("Could not stop website!");
                }
                //restart the site...
                site.Start();
                Button1.Text = "web site started";
            }
            else
            {
                throw new InvalidOperationException("Could not find website!");
            }
        }

Am i missing something in the visual studio 2012 and also when i use the following way it is giving me the list of vs project which i have created.
foreach (Site site in IIS.Sites)
            {
                //Console.WriteLine(String.Concat
                //(
                //    site.Name, " , ",
                //    site.Id, " , ",
                //    //site.State, " , ",
                //    site.Applications["/"].VirtualDirectories[0].PhysicalPath
                //));
                Console.WriteLine(site.Name.ToString());

how do i resolve this issue,i have tried changing the web.config file but it seems like not working,Can anyone help me resloving this issue.
Posted
Comments
Kornfeld Eliyahu Peter 4-Sep-14 3:39am    
Which one of the exception? Can't stop or Could not find?
Sinisa Hajnal 4-Sep-14 4:16am    
You shouldn't throw exceptions on the expected event which you're handling in if-else block, but provide sensible message and leave the function in orderly manner. Exceptions should be used in critical cases.
Chinna Suresh 4-Sep-14 6:25am    
am getting null value when i retreive the site name here
var site = server.Sites.FirstOrDefault(s => s.Name == "chinna");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900