你这样编写代码就可以解决了。用newVirDir.Properties["Path"].Value = realPath代替newVirDir.Properties["Path"].Add(realPath)这个方法就可以了。public void CreateVirtualDirectory(string nameDirectory,string realPath)
{
DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);
try
{
DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName);
newVirDir.CommitChanges();// Set Properties
newVirDir.Properties["AccessRead"].Add(true);
//newVirDir.Properties["Path"].Add(realPath);
newVirDir.Properties["Path"].Value = realPath;// Create a Application: Don't use invoke method
//newVirDir.Invoke("AppCreate",true);
// Save Changes
newVirDir.CommitChanges();
folderRoot.CommitChanges();
_iisServer.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw new Exception("Virtual Directory " + nameDirectory + " Already Exists",e);
}
}
{
DirectoryEntry folderRoot = _iisServer.Children.Find("Root",VirDirSchemaName);
try
{
DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName);
newVirDir.CommitChanges();// Set Properties
newVirDir.Properties["AccessRead"].Add(true);
//newVirDir.Properties["Path"].Add(realPath);
newVirDir.Properties["Path"].Value = realPath;// Create a Application: Don't use invoke method
//newVirDir.Invoke("AppCreate",true);
// Save Changes
newVirDir.CommitChanges();
folderRoot.CommitChanges();
_iisServer.CommitChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw new Exception("Virtual Directory " + nameDirectory + " Already Exists",e);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货