我做了快速搜索,並得到了這個鏈接 From StackOverflow虛擬目錄屬性
我得到這個錯誤信息 「未知錯誤(0x80005000)」 當它擊中
bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN");
我的要求是創建虛擬目錄並將AccessRead,IsolationMode,Scripts和Executables,ApplicationProtection設置爲中等。
得到它的工作,這裏是代碼:
注:我仍然無法得到它在Windows 7上運行,它會引發同樣的錯誤消息中包含引用System.InterOp ...目前我不在乎讓它在Windows 7上工作,我將它部署在Windows 2003上,它工作。
public void CreateVirtualDirectory(string virtualdirectory, string physicalpath)
{
try
{
///check if path exists
if (!Directory.Exists(physicalpath))
{
Log(string.Format(@"CreateVirtualDirectory; Path not found - {0}", physicalpath));
return;
}
DirectoryEntry parent = new DirectoryEntry(string.Format("IIS://{0}/W3SVC/1/Root", Environment.MachineName));
foreach (System.DirectoryServices.DirectoryEntry v in parent.Children)
{
if (v.Name == virtualdirectory)
{
try
{
parent.Invoke("Delete", new string[] { v.SchemaClassName, virtualdirectory });
}
catch
{
}
}
}
DirectoryEntry newFolder = (DirectoryEntry)parent.Invoke("Create", "IIsWebVirtualDir", virtualdirectory);
newFolder.InvokeSet("Path", physicalpath);
newFolder.Invoke("AppCreate", false);
newFolder.InvokeSet("AppFriendlyName", virtualdirectory);
const int MEDIUM_POOL = 2;
newFolder.Properties["AccessRead"][0] = true;
newFolder.Properties["AccessExecute"][0] = true;
newFolder.Properties["AccessWrite"][0] = false;
newFolder.Properties["AccessScript"][0] = true;
newFolder.Properties["AuthNTLM"][0] = true;
newFolder.Properties["AppIsolated"].Clear();
newFolder.Properties["AppIsolated"].Add(MEDIUM_POOL);
newFolder.CommitChanges();
}
catch (Exception ex)
{
Log(string.Format(@"CreateVirtualDirectory '{0}' failed; {1}", virtualdirectory, ex.Message));
}
}
我的回答以下問題,爲什麼它不Win7上工作,並且做對2K3 – bryanmac
你是正確的答案,我的壞我只是沒有之前得到它。在Windows 7的IIS 7上。我測試的Windows 7上的代碼應該在Windows 2003上工作。 – gangt