首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c#中的虚拟目录属性

问c#中的虚拟目录属性
EN

Stack Overflow用户
提问于 2011-11-11 00:53:15
回答 1查看 1K关注 0票数 1

我做了一个快速搜索,得到了这个链接From StackOverflow

我得到这个错误消息“未知错误(0x80005000)”当它点击

代码语言:javascript
复制
bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN");

我的要求是创建一个虚拟目录,并将AccessRead、IsolationMode、脚本和可执行文件、ApplicationProtection设置为媒体。

让它正常工作,这是代码:

注意:我仍然无法让它在windows 7上工作,它会引发相同的错误,并且消息包括对System.InterOp的引用.现在我不关心让它在windows 7上工作,我把它部署在windows 2003上,它可以工作。

代码语言:javascript
复制
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));
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-11 01:36:41

您正在使用DirectoryEntry创建需要在IIS中安装/配置IIS模式的网站。如果您使用的是IIS6或更高版本,则这是IIS7目录条目接口的复合模式。

如果没有安装,你将得到80005000。

如果您使用的是IIS7或更高版本(Windows 2008或Vista及更高版本),较新的(非compat模式)方法是新的托管Microsoft.Web.Administration。

http://blogs.msdn.com/b/carlosag/archive/2006/04/17/microsoftwebadministration.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8088438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档