我快速搜索并获得此链接 From StackOverflow
我收到此错误消息 "未知错误(0x80005000)" 当它击中时
bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN");
我的要求是创建一个虚拟目录并将AccessRead,IsolationMode,Scripts和Executables,ApplicationProtection设置为medium。
让它工作,这是代码:
注意:我仍然无法在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));
}
}
答案 0 :(得分:1)
您正在使用DirectoryEntry创建需要在IIS中安装/配置IIS Compat模式的网站。如果你在IIS7或更高版本上,这是IIS6目录入口接口的compat模式。
如果没有安装,你将获得80005000。
如果您使用的是IIS7或更高版本(Windows Server 2008或Vista及更高版本),则较新的(非compat模式)方法是新的托管Microsoft.Web.Administration。
http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx