Abdullahkuzhan.com gibi bir siteniz olduğunu düşünün. VDirectory1 isimli bir Application veya Virtual Folder yaratmak istediğinizi varsayacak olursak aşağıdaki kodu kullanabilirsiniz. Hosting firmaları tarafından verilen panellerde arayüzler ile otomatik oluşturduğunuz Virtual’lar kod ile aşağıdaki gibi oluşturulabilir. Bunu zamanında 50+ Virtual’ı olan bir siteyi bir başka makineye taşırken yazmıştım(IIS’te taşınabilir tabiki).
string strSchema = "IIsWebVirtualDir";
string strRootSubPath = "/W3SVC/1/Root";
DirectoryEntry deRoot = new DirectoryEntry("IIS://" + "localhost" + strRootSubPath);
try
{
deRoot.RefreshCache();
DirectoryEntry deNewVDir = deRoot.Children.Add("AbdullahKuzhan.com/"+"VDirectory1", strSchema);
deNewVDir.Properties["Path"].Insert(0, "d:\sites\abdullahkuzhan.com\MyFolder\");
deNewVDir.CommitChanges();
deRoot.CommitChanges();
if (strSchema == "IIsWebVirtualDir")
deNewVDir.Invoke("Create", true); // "AppCreate" dersen application olarak yaratır, "Create" dersen virtual folder olarak yaratır.
deNewVDir.CommitChanges();
deRoot.CommitChanges();
deNewVDir.Close();
deRoot.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
follow: