zoukankan      html  css  js  c++  java
  • 设置IIsWebDirectory对象属性

    /// <summary>
            /// System.DirectoryServices.DirectoryEntry De = new DirectoryEntry();
            /// De.Path = @"IIS://localhost/W3SVC/1/ROOT/Dir1/Dir2/Dir3";
            /// RecursiveSetIIsWebDirectory(De);
            /// De.Properties["AccessFlags"][0] = 513;
            /// De.CommitChanges();
            /// </summary>
            /// <param name="IIsWebDirectoryObject"></param>
            public void RecursiveSetIIsWebDirectory(DirectoryEntry IIsWebDirectoryObject)
            {
                try
                {
                    bool temp = DirectoryEntry.Exists(IIsWebDirectoryObject.Path);
                }
                catch
                {
                    string DirName = "";
                    string Path = IIsWebDirectoryObject.Path;
                    string ParentPath = "";

                    DirName = Path.Substring(Path.LastIndexOf(@"/") + 1);
                    ParentPath = Path.Substring(0, Path.Length - (DirName.Length + 1));

                    DirectoryEntry ParentDe = new DirectoryEntry(ParentPath);
                    RecursiveSetIIsWebDirectory(ParentDe); // Call for parent directory

                    // Create a new entry in the IIS Metabase
                    DirectoryEntry newChild;
                    newChild = ParentDe.Children.Add(DirName, "IIsWebDirectory"); // Create the new IIsWebDirectory
                    newChild.CommitChanges(); // Commit the changes. Create a new IIsWebDirectory
                }
            }

            /// <summary>
            /// System.DirectoryServices.DirectoryEntry De = new DirectoryEntry();
            /// De.Path = @"IIS://localhost/W3SVC/1/ROOT/Dir1/Dir2/Dir3/file.txt";
            /// RecursiveSetIIsWebFile(De, 0);
            /// De.Properties["AccessFlags"][0] = 513;
            /// De.CommitChanges();
            /// </summary>
            /// <param name="DirectoryEntryObject"></param>
            /// <param name="depth"></param>
            public void RecursiveSetIIsWebFile(DirectoryEntry DirectoryEntryObject, int depth)
            {
                try
                {
                    bool temp = DirectoryEntry.Exists(DirectoryEntryObject.Path);
                }
                catch
                {
                    string DirName = "";
                    string Path = DirectoryEntryObject.Path;
                    string ParentPath = "";

                    DirName = Path.Substring(Path.LastIndexOf(@"/") + 1);
                    ParentPath = Path.Substring(0, Path.Length - (DirName.Length + 1));

                    DirectoryEntry ParentDe = new DirectoryEntry(ParentPath);
                    RecursiveSetIIsWebFile(ParentDe, depth + 1);

                    DirectoryEntry newChild;
                    if (depth == 0)
                    {
                        newChild = ParentDe.Children.Add(DirName, "IIsWebFile"); // Create the new IIsWebFile
                    }
                    else
                    {
                        newChild = ParentDe.Children.Add(DirName, "IIsWebDirectory"); // Create the new IIsWebDirectory
                    }
                    newChild.CommitChanges();
                }
            }

  • 相关阅读:
    Orchard源码分析(4.3):Orchard.Events.EventsModule类(Event Bus)
    Orchard源码分析(4.2):Orchard.Logging.LoggingModule类
    Orchard源码分析(4.1):Orchard.Environment.CollectionOrderModule类
    Orchard源码分析(4):Orchard.Environment.OrchardStarter类
    Orchard源码分析(3):Orchard.WarmupStarter程序集
    Orchard源码分析(2):Orchard.Web.MvcApplication类(Global)
    MSSQL
    MSSQL
    C#、WinForm、ASP.NET
    C#、WinForm、ASP.NET
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1709771.html
Copyright © 2011-2022 走看看