Hi ,
I find a solution for adding websites to IIS with asp.net, this is very amazing! the first step is adding Microsoft.Web.Administration.dll to your project's refrences, it is at "windir\system32\inetsrv\" folder.
Here is the code:
C# version:
using System;
using Microsoft.Web.Administration;
class Program
{
static void Main(string[] args)
{
ServerManager mgr = new ServerManager();
mgr.Sites.Add("MyWebSite", "http", "198.1.1.0:80:",
@"d:\MyWebSiteRootWebAppRootVirDir");
mgr.CommitChanges();
}
}
VB.NET version:
Imports Microsoft.VisualBasic
Imports Microsoft.Web.Administration
Imports System.Configuration
Public Class clsCreateWebsite
Public Function createWebsite(ByVal websiteName As String, ByVal domainName As String, ByVal physicalPath As String) As Boolean
Dim IIS_manager As New ServerManager
Try
IIS_manager.Sites.Add(websiteName, "http", "*:80:" + domainName, physicalPath) IIS_manager.CommitChanges()
Return True
Catch ex As Exception
Return False
Finally
IIS_manager = Nothing
End Try
End Function
End Class
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5