Showing posts with label website. Show all posts
Showing posts with label website. Show all posts

Monday, November 10, 2008

Create and Delete Virtual Directory Programmatically

create a function to create a new virtual directory and set some properties of the new virtual directory.

public void CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
DirectoryEntry NewVirtualDir;
NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
NewVirtualDir.Properties["Path"][0] = Path;
NewVirtualDir.Properties["AccessScript"][0] = AccessScript;NewVirtualDir.CommitChanges();
}
You can call this function like
CreateNewVirtualDirectory(1, "MyNewVirtualDirectory", @"C:\Inetpub\wwwroot\MyDir", true)


create a function to Delete virtual directory .

public void DeleteVirtualDirectory(int ServerId, string VirtualDirName)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
Object[] Parameters = {"IIsWebVirtualDir",VirtualDirName};
Parent.Invoke("Delete",Parameters );
}

Thursday, October 9, 2008

Error while trying to run project: Unable to start debugging on the web server

Error while trying to run project: Unable to start debugging on the web server
About the “Error while trying to run project: Unable to start debugging on the web server.” Error.

Open your Internet Information Services manager and from the [your machine]/Web Sites/ Default Web Site node select the virtual folder which stores your project. Right Click and select Properties to select the ASP.NET tab page. Make sure the correct version ASP.NET Version is selected.