[英]virtual directory properties in c#
我進行了快速搜索,並從StackOverflow獲得了此鏈接
我遇到此錯誤消息“未知錯誤(0x80005000)”
bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN");
我的要求是創建一個虛擬目錄,並將AccessRead,IsolationMode,腳本和可執行文件,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));
}
}
您正在使用DirectoryEntry創建需要在IIS中安裝/配置IIS兼容模式的網站。 如果您使用的是IIS7或更高版本,則這是IIS6目錄輸入接口的兼容模式。
如果未安裝,則會得到80005000。
如果您使用的是IIS7或更高版本(Windows Server 2008或Vista和更高版本),則更新的(非兼容模式)方法是新的托管Microsoft.Web.Administration。
http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.