亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

System.DirectoryServices

系統 1586 0
可以的,ADSI, ? WMI, ? System.Directory, ? ABO等四種方式都可以操作 ?
? 具體可以查看一下MSDN里的Web ? Development\Server ? Technologies\Internet ? Information ? Services ? SDK\IIS ? Programmatic ? Administration ? SDK\Using ? IIS ? Programmatic ? Administration,里面有很多例子。 ?
? 不過你要確保訪問A服務器上的asp.net的應用程序具有B服務器的IIS的管理權限。 ?
? ?
? 下面這個是用System.DirectoryServices創建site和vitual ? directory的例子 ?
? ?
? Internet ? Service ? Providers ? (ISPs) ? that ? provide ? Web ? hosting ? services ? to ? customers, ? need ? to ? configure ? their ? IIS ? servers ? frequently. ? Some ? ISPs ? use ? forms ? to ? programmatically ? enroll ? new ? customers ? and ? add ? a ? new ? Web ? site ? or ? virtual ? directory ? for ? them. ? The ? new ? site ? or ? virtual ? directory ? can ? be ? put ? in ? a ? new ? application ? pool ? to ? isolate ? it ? from ? other ? applications ? on ? the ? server. ?
? ?
? Example ? Code ?
? The ? following ? example ? shows ? you ? how ? to ? use ? the ? C# ? programming ? language ? to ? add ? a ? new ? Web ? site ? and ? virtual ? directory ? with ? System.DirectoryServices. ?
? ?
? To ? keep ? this ? code ? example ? concise, ? it ? does ? not ? include ? code ? access ? security ? (CAS) ? parameters ? or ? parameter ? checking. ? For ? more ? information, ? see ? Code ? Access ? Security ? and ? Validating ? User ? Input ? to ? Avoid ? Attacks. ? Additionally, ? you ? can ? instantiate ? your ? System.DirectoryServices.DirectoryEntry ? object ? with ? an ? authentication ? parameter. ? ?
? ?
? C# ? ? Copy ? Code ? ?
? using ? System; ?
? using ? System.IO; ?
? using ? System.DirectoryServices; ?
? using ? System.Reflection; ?
? using ? System.Runtime.InteropServices; ?
? using ? System.Collections; ?
? ?
? namespace ? System_DirectoryServices_DirectoryEntry_ConfigIIS ?
? { ?
? ? ? class ? Program ?
? ? ? { ?
? ? ? ? ? static ? void ? Main(string[] ? args) ?
? ? ? ? ? { ?
? ?
? ... ?
? ? ? ? ? ? ? ? ? CreateSite("IIS://Localhost/W3SVC", ? "555", ? "MySite", ? "D:\\Inetpub\\Wwwroot"); ?
? ?
? ... ?
? ? ? ? ? ? ? ? ? SetSingleProperty("IIS://Localhost/W3SVC/555", ? "ServerBindings", ? ":8080:"); ?
? ?
? ... ?
? ? ? ? ? ? ? ? ? CreateVDir("IIS://Localhost/W3SVC/1/Root", ? "MyVDir", ? "D:\\Inetpub\\Wwwroot"); ?
? ?
? ... ?
? ? ? ? } ?
? ?
? ... ?
? ? ? ? ? static ? void ? CreateSite(string ? metabasePath, ? string ? siteID, ? string ? siteName, ? string ? physicalPath) ?
? ? ? ? ? { ?
? ? ? ? ? ? ? // ? ? metabasePath ? is ? of ? the ? form ? "IIS://<servername>/<service>" ?
? ? ? ? ? ? ? // ? ? ? ? for ? example ? "IIS://localhost/W3SVC" ? ?
? ? ? ? ? ? ? // ? ? siteID ? is ? of ? the ? form ? "<number>", ? for ? example ? "555" ?
? ? ? ? ? ? ? // ? ? siteName ? is ? of ? the ? form ? "<name>", ? for ? example, ? "My ? New ? Site" ?
? ? ? ? ? ? ? // ? ? physicalPath ? is ? of ? the ? form ? "<drive>:\<path>", ? for ? example, ? "C:\Inetpub\Wwwroot" ?
? ? ? ? ? ? ? Console.WriteLine("\nCreating ? site ? {0}/{1}, ? mapping ? the ? Root ? application ? to ? {2}:", ? ?
? ? ? ? ? ? ? ? ? ? ? metabasePath, ? siteID, ? physicalPath); ?
? ?
? ? ? ? ? ? ? try ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? DirectoryEntry ? service ? = ? new ? DirectoryEntry(metabasePath); ?
? ? ? ? ? ? ? ? ? string ? className ? = ? service.SchemaClassName.ToString(); ?
? ? ? ? ? ? ? ? ? if ? (className.EndsWith("Service")) ?
? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntries ? sites ? = ? service.Children; ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntry ? newSite ? = ? sites.Add(siteID, ? (className.Replace("Service", ? "Server"))); ?
? ? ? ? ? ? ? ? ? ? ? newSite.Properties["ServerComment"][0] ? = ? siteName; ?
? ? ? ? ? ? ? ? ? ? ? newSite.CommitChanges(); ?
? ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntry ? newRoot; ?
? ? ? ? ? ? ? ? ? ? ? newRoot ? = ? newSite.Children.Add("Root", ? "IIsWebVirtualDir"); ?
? ? ? ? ? ? ? ? ? ? ? newRoot.Properties["Path"][0] ? = ? physicalPath; ?
? ? ? ? ? ? ? ? ? ? ? newRoot.Properties["AccessScript"][0] ? = ? true; ?
? ? ? ? ? ? ? ? ? ? ? newRoot.CommitChanges(); ?
? ?
? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Done. ? Your ? site ? will ? not ? start ? until ? you ? set ? the ? ServerBindings ? or ? SecureBindings ? property."); ?
? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? else ?
? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Failed. ? A ? site ? can ? only ? be ? created ? in ? a ? service ? node."); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? catch ? (Exception ? ex) ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? Console.WriteLine("Failed ? in ? CreateSite ? with ? the ? following ? exception: ? \n{0}", ? ex.Message); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? } ?
? ?
? ... ?
? ? ? ? ? static ? void ? SetSingleProperty(string ? metabasePath, ? string ? propertyName, ? object ? newValue) ?
? ? ? ? ? { ?
? ? ? ? ? ? ? // ? ? metabasePath ? is ? of ? the ? form ? "IIS://<servername>/<path>" ?
? ? ? ? ? ? ? // ? ? ? ? for ? example ? "IIS://localhost/W3SVC/1" ? ?
? ? ? ? ? ? ? // ? ? propertyName ? is ? of ? the ? form ? "<propertyName>", ? for ? example ? "ServerBindings" ?
? ? ? ? ? ? ? // ? ? value ? is ? of ? the ? form ? "<intStringOrBool>", ? for ? example, ? ":80:" ?
? ? ? ? ? ? ? Console.WriteLine("\nSetting ? single ? property ? at ? {0}/{1} ? to ? {2} ? ({3}):", ?
? ? ? ? ? ? ? ? ? ? ? metabasePath, ? propertyName, ? newValue, ? newValue.GetType().ToString()); ?
? ?
? ? ? ? ? ? ? try ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntry ? path ? = ? new ? DirectoryEntry(metabasePath); ?
? ? ? ? ? ? ? ? ? ? ? PropertyValueCollection ? propValues ? = ? path.Properties[propertyName]; ?
? ? ? ? ? ? ? ? ? ? ? string ? oldType ? = ? propValues.Value.GetType().ToString(); ?
? ? ? ? ? ? ? ? ? ? ? string ? newType ? = ? newValue.GetType().ToString(); ?
? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Old ? value ? of ? {0} ? is ? {1} ? ({2})", ? propertyName, ? propValues.Value, ? oldType); ?
? ? ? ? ? ? ? ? ? ? ? if ? (newType ? == ? oldType) ?
? ? ? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? path.Properties[propertyName][0] ? = ? newValue; ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? path.CommitChanges(); ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("Done"); ?
? ? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? ? ? else ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Failed ? in ? SetSingleProperty; ? type ? of ? new ? value ? does ? not ? match ? property"); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? catch ? (Exception ? ex) ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? if ? ("HRESULT ? 0x80005006" ? == ? ex.Message) ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Property ? {0} ? does ? not ? exist ? at ? {1}", ? propertyName, ? metabasePath); ?
? ? ? ? ? ? ? ? ? ? ? else ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine("Failed ? in ? SetSingleProperty ? with ? the ? following ? exception: ? \n{0}", ? ex.Message); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? } ?
? ?
? ... ?
? ? ? ? ? static ? void ? CreateVDir(string ? metabasePath, ? string ? vDirName, ? string ? physicalPath) ?
? ? ? ? ? { ?
? ? ? ? ? ? ? // ? ? metabasePath ? is ? of ? the ? form ? "IIS://<servername>/<service>/<siteID>/Root[/<vdir>]" ?
? ? ? ? ? ? ? // ? ? ? ? for ? example ? "IIS://localhost/W3SVC/1/Root" ? ?
? ? ? ? ? ? ? // ? ? vDirName ? is ? of ? the ? form ? "<name>", ? for ? example, ? "MyNewVDir" ?
? ? ? ? ? ? ? // ? ? physicalPath ? is ? of ? the ? form ? "<drive>:\<path>", ? for ? example, ? "C:\Inetpub\Wwwroot" ?
? ? ? ? ? ? ? Console.WriteLine("\nCreating ? virtual ? directory ? {0}/{1}, ? mapping ? the ? Root ? application ? to ? {2}:", ?
? ? ? ? ? ? ? ? ? ? ? metabasePath, ? vDirName, ? physicalPath); ?
? ?
? ? ? ? ? ? ? try ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? DirectoryEntry ? site ? = ? new ? DirectoryEntry(metabasePath); ?
? ? ? ? ? ? ? ? ? string ? className ? = ? site.SchemaClassName.ToString(); ?
? ? ? ? ? ? ? ? ? if ? ((className.EndsWith("Server")) ? || ? (className.EndsWith("VirtualDir"))) ?
? ? ? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntries ? vdirs ? = ? site.Children; ?
? ? ? ? ? ? ? ? ? ? ? DirectoryEntry ? newVDir ? = ? vdirs.Add(vDirName, ? (className.Replace("Service", ? "VirtualDir"))); ?
? ? ? ? ? ? ? ? ? ? ? newVDir.Properties["Path"][0] ? = ? physicalPath; ?
? ? ? ? ? ? ? ? ? ? ? newVDir.Properties["AccessScript"][0] ? = ? true; ?
? ? ? ? ? ? ? ? ? ? ? // ? These ? properties ? are ? necessary ? for ? an ? application ? to ? be ? created. ?
? ? ? ? ? ? ? ? ? ? ? newVDir.Properties["AppFriendlyName"][0] ? = ? vDirName; ?
? ? ? ? ? ? ? ? ? ? ? newVDir.Properties["AppIsolated"][0] ? = ? "1"; ?
? ? ? ? ? ? ? ? ? ? ? newVDir.Properties["AppRoot"][0] ? = ? "/LM" ? + ? metabasePath.Substring(metabasePath.IndexOf("/", ? ("IIS://".Length))); ?
? ?
? ? ? ? ? ? ? ? ? ? ? newVDir.CommitChanges(); ?
? ?
? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Done."); ?
? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? ? else ?
? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(" ? Failed. ? A ? virtual ? directory ? can ? only ? be ? created ? in ? a ? site ? or ? virtual ? directory ? node."); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? catch ? (Exception ? ex) ?
? ? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? ? Console.WriteLine("Failed ? in ? CreateVDir ? with ? the ? following ? exception: ? \n{0}", ? ex.Message); ?
? ? ? ? ? ? ? } ?
? ? ? ? ? } ?
? ?
? ... ?
? ? ? } ?
? }

System.DirectoryServices


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲综合一 | 九九九九热精品视频 | 国产高清精品一区 | 九九视频高清视频免费观看 | 狠狠色噜噜狠狠狠狠2021天天 | 国产精品日韩欧美在线第3页 | 中文字幕久精品免费视频蜜桃视频 | 亚洲精品中文字幕一区在线 | 色婷亚洲| 91资源在线播放 | 色天天综合 | 国产在线视频www色 国产在线视频凹凸分类 | 久久免费精品国产视频 | 欧美国产亚洲一区 | 99热精品久久 | 九九爱精品 | 中文字幕日韩精品一区口 | 欧美精品综合一区二区三区 | 久久这里只有精品1 | 日本亚洲一区二区 | 国产精品毛片一区二区三区 | 一区二区成人国产精品 | 黄毛片免费 | 欧美一级特黄一片免费 | 天天色天天射天天干 | 一区二区国产在线观看 | 久久不射网 | 成人毛片免费免费 | 狠狠插狠狠干 | 91福利片 | 亚洲天码中文字幕第一页 | 色综合合久久天天综合绕视看 | 久久久久久久99精品免费 | 国产在线精品观看一区 | 伊人久久精品线影院 | 午夜在线观看免费影院 | 99久久99热精品免费观看国产 | 九九福利 | 五月亭亭免费高清在线 | 一级毛片视频免费观看 | 色偷偷7777www |