Hi,
i work with windows server 2008r2, visual studio 2010, and iis7. I googled out c# code to programatically create a website in iis, assign an application pool to it, and do the authorization settings and the appli9caiton pool settings. After i create a website and appllication pool through c# code i instantiate an visual studio installer(.msi file) that will install the applications under the newly created website.
THE PROBLEM: Once i finish everything and expand my newly created site i see my applications installed. when i click on them under the features tab of iis i dont see the ASP.NET tab. because of that the other tabs(iis & managemant) are slao not functional. and when i attempot to open any of the aspx pages of my applicaitons it shows http 503: service not available error. here is the code i have used.
your help would be greatly appreciated. Thanks in advance.
string Folderpath = @"c:\inetpub\wwwroot\" + textBox3.Text;
if (!Directory.Exists(Folderpath))
{
Directory.CreateDirectory(Folderpath);
MessageBox.Show("New Folder created!", " Message ");
}
else
{
MessageBox.Show("The Folder already exist. Please enter a different name!", " Alert!!! ");
this.Hide();
System.Windows.Forms.Application.Restart();
}
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
try
{
TcpListener tcpListener = new TcpListener(ipAddress, Convert.ToInt32(textBox2.Text));
tcpListener.Start();
MessageBox.Show("Port No. is available" , "Message");
}
Catch (SocketException ex)
{
MessageBox.Show(ex.Message, "Please enter a different port number");
this.Hide();
System.Windows.Forms.Application.Restart();
}
string sitepath = @"C:\inetpub\wwwroot\" + textBox3.Text;
ServerManager serverManager = new ServerManager();
if (Directory.Exists(sitepath))
{
try
{
Directory.CreateDirectory(sitepath);
Site mySite = serverManager.Sites.Add(textBox1.Text, sitepath, Convert.ToInt32(textBox2.Text));
mySite.ServerAutoStart = true;
MessageBox.Show("site created" , "Message");
}
catch (Exception site)
{
MessageBox.Show(site.Message, "Site Name error");
this.Hide();
System.Windows.Forms.Application.Restart();
}
try
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", textBox1.Text);
anonymousAuthenticationSection["enabled"] = false;
ConfigurationSection basicAuthenticationSection = config.GetSection("system.webServer/security/authentication/basicAuthentication", textBox1.Text);
basicAuthenticationSection["enabled"] = false;
ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", textBox1.Text);
windowsAuthenticationSection["enabled"] = true;
}
catch(Exception config)
{
MessageBox.Show(config.Message,"Configuration error");
this.Hide();
System.Windows.Forms.Application.Restart();
}
try
{
serverManager.ApplicationPools.Add(textBox4.Text);
ApplicationPool apppool = serverManager.ApplicationPools[textBox4.Text];
Site site = serverManager.Sites[textBox1.Text];
serverManager.Sites[textBox1.Text].Applications[0].ApplicationPoolName = textBox4.Text;
Configuration config = serverManager.GetWebConfiguration("Default Web Site");
ConfigurationSection section = config.GetSection("system.webServer/defaultDocument");
ConfigurationAttribute enabled = section.GetAttribute("enabled");
enabled.Value = true;
config = serverManager.GetApplicationHostConfiguration();
section = config.GetSection("system.webServer/defaultDocument", textBox1.Text);
enabled = section.GetAttribute("enabled");
enabled.Value = false;
apppool.ManagedPipelineMode = ManagedPipelineMode.Classic;
apppool.ManagedRuntimeVersion = "V4.0";
apppool.AutoStart = true;
}
catch(Exception pool)
{
MessageBox.Show(pool.Message,"Applicationpool error");
this.Hide();
System.Windows.Forms.Application.Restart();
}
serverManager.CommitChanges();
DialogResult dlg;
dlg = MessageBox.Show("Website and its settings has been successfully configured. Please click on proceed", "Message" , MessageBoxButtons.OK);
if (dlg == DialogResult.OK)
{
Proceed.Enabled = true;
Next.Enabled = false;
}
}