ãšã³ããªãŒ
ãã°ããåãç§ã¯ããã°ã©ã ã§ãªã¢ãŒãIISãå¶åŸ¡ãããããã¢ãžã¥ãŒã«ãšããŠå®è£ ããæè¯ã®æ¹æ³ãèŠã€ããããšãä»»ãããŸããã ãã®ã¿ã¹ã¯ã¯é¢çœããå€ãã®å°é£ã䌎ããããç§ã®çµéšãå ±æããããšæããŸãã
å®è£ ãããã¢ãžã¥ãŒã«ã®åºæ¬çãªèŠä»¶ã®ãªã¹ãã¯æ¬¡ã®ãšããã§ãã
- IISã§åºæ¬çãªæäœãå®è¡ããæ©èœïŒ
- ãŠã§ããµã€ãã®äœæ
- ä»®æ³ã¢ããªã±ãŒã·ã§ã³ã®äœæ
- ä»®æ³ãã£ã¬ã¯ããªã®äœæ
- SSL蚌ææžã®ã€ã³ã¹ããŒã«ãå«ãããµã€ãã®ãã€ã³ãã®èšå®
- 詳现ãªã¢ããªã±ãŒã·ã§ã³ããŒãªã³ã°
- ç°ãªããã¡ãŒã ãµãŒããŒäžã®è€æ°ã®IISã«ãã䞊åæäœã®ãµããŒã
- IISããŒãžã§ã³8.0ã®ãµããŒãïŒä»¥åã®ããŒãžã§ã³ããµããŒãããå¿ èŠã¯ãããŸããïŒã
ã€ãŸããã¢ãžã¥ãŒã«ã¯ã IISãããŒãžã£ãŒãä»ããŠå®è¡ã§ããå®è³ªçã«ãã¹ãŠãå®è¡ã§ããã¯ãã§ãã
åé¡ã解決ããã®ã«é©ãã3ã€ã®ããŒã«ãèŠã€ããŠèª¿æ»ããŸããã
æ€èšããåãªãã·ã§ã³ã䜿çšããŠãã¹ãã¢ããªã±ãŒã·ã§ã³ãäœæããåŸãæãææãªãã®ãšããŠMicrosoft.Web.AdministrationãéžæããŸããã
ããŒã«ã®ã¡ãœãããç解ããã®ã¯éåžžã«é£ããããšã©ãŒã®å¯èœæ§ãé«ããªããããæåã®ãªãã·ã§ã³ã¯æåŠããŸããã åæã«ããããæ±ãããšã¯ãCOMã³ã³ããŒãã³ããæ±ãããšã«äŒŒãŠããŸãã
WMIã䜿çšããŠãµã€ããäœæããäŸïŒ
DirectoryEntry IIS = new DirectoryEntry("IIS://localhost/W3SVC"); object[] bindings = new object[] { "127.0.0.1:4000:", ":8000:" }; IIS.Invoke("CreateNewSite", "TestSite", bindings, "C:\\InetPub\\WWWRoot");
2çªç®ã®ãªãã·ã§ã³ã¯ãXMLæ§æãã¡ã€ã«ãæäœããããšã§ãã ã€ãŸããWebãµãŒããŒäžã®ã«ãŒãweb.configãã¡ã€ã«ãã»ãšãã©æåã§å€æŽããããšã«ãªã£ãŠããŸãã ãåç¥ã®ããã«ããã®ãªãã·ã§ã³ã¯ç§ã«ãé©ããŠããŸããã
3çªç®ã®ãªãã·ã§ã³ã§ã¯ããµã€ããäœæããéçºè ã®ããã«ãã¹ãŠã®äœã¬ãã«ã®äœæ¥ãè¡ãããšãã§ããŸããã ãã®ããŒã«ã®ãã1ã€ã®å©ç¹ã¯ã IISãããŒãžã£ãŒããã®ç¹å®ã®ã©ã€ãã©ãªã䜿çšããŠãå©çšå¯èœãªãã¹ãŠã®æäœãå®è¡ããããšã§ãã
ãã¡ããããœãªã¥ãŒã·ã§ã³ã®å®è£ ã«ã¯ãŸã å°é£ããããŸããã ãã®Microsoft.Web.Administrationãå¿ èŠãªæ¹æ³ã§åäœãããããã«ãç§ã¯å€ãã®Googleã®æéãè²»ãããŸããã ã€ã³ã¿ãŒãããã§ã¯ããã®ã©ã€ãã©ãªãæäœããæ¹æ³ãããã§äœãã§ããããªã©ãå€ãã®æ å ±ãèŠã€ããããšãã§ããŸãã ãã ãããããã®æ å ±ã¯ãã¹ãŠãããŸããŸãªèšäºã«æ£åšããŠããŸãã ããã¯ãMicrosoft.Web.Administrationã®ãèœãšãç©Žã®äžçã«æ²¡é ãããç§ã®çµéšã«ã€ããŠæžãããšãç§ã«ä¿ããŸããã ç§ãééãããã¹ãŠã®åé¡ãšãã®è§£æ±ºçãéããããšããŸããã çªç¶èª°ãã䟿å©ã«ãªããŸãã
ããã§ã¯ãæè¡çãªéšåããå§ããŸãããã
ã·ã¹ãã æ§æ
WebãµãŒããŒã®ãã¡ãŒã ãããããããããIIS 8.0ãåããWindows Server 2012 Standardã«ãã£ãŠç®¡çãããŠããŸã ã ã¢ãžã¥ãŒã«ã䜿çšããŠWindowsãµãŒãã¹ãå®è¡ããŠããå¥ã®ã¢ããªã±ãŒã·ã§ã³ãµãŒããŒããããŸãã IISã¯ãã®ãµãŒããŒã«å±éãããŸããã ã¢ããªã±ãŒã·ã§ã³ãµãŒããŒããWebãµãŒããŒã管çããå¿ èŠããããŸãã
éçº
Microsoft.Web.Administrationæ¥ç¶
æåã®åé¡ã¯ãã©ã€ãã©ãªããã¹ããã段éã§ããã«çŸããŸããã ãããžã§ã¯ãã«æ¥ç¶ãããµã€ããäœæããããšã«ãªã£ãŠããã³ãŒããèšè¿°ããHRESULTããã¢ã¯ã»ã¹ãšã©ãŒäŸå€0x80070005ïŒE_ACCESSDENIEDïŒãåãåããŸããã åæ§ã®åé¡ã«é¢ããå€ãã®èª¬æïŒ stackoverflow.com/questions/8963641/permissions-required-to-use-microsoft-web-administrationãªã© ïŒãèªãã åŸã«å€æããããã«ãMicrosoft.Web.Administrationã«ã¯ã«ãŒãweb.configãã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããã®ç®¡çè æš©éãå¿ èŠã§ãã
ããŠããªã¢ãŒããµãŒããŒäžã«ãŠãŒã¶ãŒåãšãã¹ã¯ãŒãã䜿çšããŠãŠãŒã¶ãŒãäœæããŸãã ããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒäžã«åããŠãŒã¶ãŒåãšãã¹ã¯ãŒãã§åããŠãŒã¶ãŒãäœæããŸãïŒããã¯éèŠã§ããããããªããšãã¢ããªã±ãŒã·ã§ã³ã¯ãªã¢ãŒããã·ã³ã«ãã°ã€ã³ããŸããïŒã å§ããŸãã åãåé¡ïŒ
ã¢ã¯ã»ã¹åé¡ããã詳现ã«èª¿æ»ããŸãã adminãŠãŒã¶ãŒãäœæããã ãã§ã¯äžååã§ããããšãããããŸããã çµå±ã®ãšãããWindows Vistaããå§ããŠãUACã·ã¹ãã ãç»å ŽããŸããã ãŸãããã®ã·ã¹ãã ãç解ããŠããã³ã³ãã¥ãŒã¿ãŒç®¡çè ã§ããããŸã£ãã管çè ã§ã¯ãªããé«åºŠãªæš©éãæã€ãŠãŒã¶ãŒã§ãã ã¢ããªã±ãŒã·ã§ã³ãæ©èœããã«ã¯ããªã¢ãŒããµãŒããŒã§UACãç¡å¹ã«ããå¿ èŠãããããšãããããŸãã ãã ããWindowsã®ç®¡çããUACãç¡å¹ã«ããã ãã§ã¯ååã§ã¯ãããŸããã åé¡ã¯æ®ã£ãŠããŸãã UACãå®å šã«ç¡å¹ã«ããå¿ èŠããããŸãã åç §ã«ããèšäºã§èª¬æãããŠããããã«ãã¬ãžã¹ããªãä»ããŠãããè¡ããŸããã ã¯ããåæããŸãããããã¯å®å šã§ã¯ãããŸããã ãããããããå¯äžã®è§£æ±ºçã§ãã 幞ããªããšã«ã顧客ã¯åæããŸãã
ã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããšããŠããŸãã ãŠãŒã¬ã«ïŒ ãµã€ããäœæãããŸããã ã ãããå ã«é²ãããšãã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ããã¹ããµãŒããŒã«å±éãããåŸã2çªç®ã®æ§æã®åé¡ãçºçããŸãããã¢ãžã¥ãŒã«ã¯Microsoft.Web.Administrationã©ã€ãã©ãªãèŠã€ããããšãã§ããããšã©ãŒã§ã¯ã©ãã·ã¥ããŸããã ãµãŒããŒäžã®GACã§ã¯ãç°ãªãããŒãžã§ã³ã®ãã«ãã§ããããšãå€æããŸããã ãã®å°é£ã«å¯ŸåŠããããã«ããããžã§ã¯ãBinã«ç®çã®ã©ã€ãã©ãªã®ã³ããŒãå«ããããšã決å®ãããŸããã
ã©ã€ãã©ãªã®æ¥ç¶ã«é¢é£ããæåŸã®åé¡ããã¢ã»ã³ããªã®ããŒãžã§ã³ç®¡çã®ããã«çºçããŸããã ã¢ã¯ãã£ããªéçºã®æ®µéã§ãããŒãžã§ã³7.0.0.0ããã³7.5.0.0ã®ã©ã€ãã©ãªãèŠã€ãããŸãããã2çªç®ã®æ¹æ³ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ããŒã«ã«AlwaysRunningãã€ã³ã¹ããŒã«ãããªã©ãéèŠãªãã®ã®å®è£ ãç°¡çŽ åããŸããã ãããã£ãŠãæåã«æ¥ç¶ããŸããã ãããããã¹ããµãŒããŒã«ã¢ããããŒãããåŸãã¢ããªã±ãŒã·ã§ã³ã¯åã³ã¯ã©ãã·ã¥ããŸããã Microsoft.Web.Administration 7.5.0.0ã¯IIS Expressã§ã®ã¿æ©èœããããšãããããŸããã ãããã£ãŠãæ¬æ ŒçãªIISã管çããäºå®ã®å Žåã¯ãããŒãžã§ã³7.0.0.0ã䜿çšããŠãã ããã
ãããã¯ãMicrosoft.Web.Administrationã©ã€ãã©ãªãæ¥ç¶ãããšããããã³ã¿ã¹ã¯ã解決ããããã®æºåã«ãããäž»ãªåé¡ã§ããã å ã¯ã顧客ã®èŠä»¶ã«å¿ããæ©èœã®å®è£ ã§ããã ãããã«ã€ããŠããã«èª¬æããŸãã
å®è£ èŠä»¶
ã¢ãžã¥ãŒã«ã«å®è£ ããã¡ãœããã«ã¯ãäžè¬çãªãã®ãšãé ãæã¡ç ããªããã°ãªããªãã£ããã®ããããŸãã ã€ã³ã¿ãŒãããã§ç°¡åã«èŠã€ããããšãã§ãããã®ã«ã€ããŠã¯èª¬æããŸãããMicrosoft.Web.Administrationã©ã€ãã©ãªã®ã¡ãœããã®ååãããšãã°Webãµã€ãããã®ãã€ã³ããŒã®äœæããæ¢ã«æãããªããšã¯ãã¹ãŠèª¬æããŸãã 代ããã«ãç§ãèããªããã°ãªããªãåé¡ãããã³ã€ã³ã¿ãŒãããã§è§£æ±ºçãèŠã€ããããšãå°é£ã§ãã£ãïŒãŸãã¯ãŸã£ãã解決ããªãã£ãïŒåé¡ã«éäžããŸãã
ãã«ãã¹ã¬ãããšãã«ãã¿ã¹ã¯
ã¢ãžã¥ãŒã«ã®èŠä»¶ã«å¿ããŠã1ã€ãŸãã¯è€æ°ã®ãªã¢ãŒããµãŒããŒäžã«è€æ°ã®Webãµã€ãã䞊è¡ããŠäœæã§ããããã«ããå¿ èŠããããŸããã åæã«ã2ã€ã®ã¹ã¬ããã¯1ã€ã®ãªã¢ãŒãIISãå¶åŸ¡ã§ããŸããã å®éãããã¯åãã«ãŒãweb.configãã¡ã€ã«ãå€æŽããããšãæå³ããŸãã ãããã£ãŠãWebãµãŒããŒã®ååã§ããã¯ã¹ã¬ãããäœæããããšã決å®ãããŸããã ããã¯æ¬¡ã®ããã«è¡ãããŸãã
private ServerManager _server; private static readonly ConcurrentDictionary<string, object> LockersByServerName = new ConcurrentDictionary<string, object>(); private object Locker { get { return LockersByServerName.GetOrAdd(ServerName, new object()); } } private void ConnectAndProcess(Action handler, CancellationToken token) { token.ThrowIfCancellationRequested(); lock (Locker) { try { _server = ServerManager.OpenRemote(ServerName); token.ThrowIfCancellationRequested(); try { handler(); } catch (FileLoadException) { // try again token.ThrowIfCancellationRequested(); if (_server != null) _server.Dispose(); _server = ServerManager.OpenRemote(ServerName); token.ThrowIfCancellationRequested(); handler(); } } finally { if(_server != null) _server.Dispose(); _server = null; } } }
ãã®äŸã§ã¯ãServerNameã¯ããŒã«ã«ãããã¯ãŒã¯äžã®ã³ã³ãã¥ãŒã¿ãŒã®NetBIOSåã§ãã
éçºãããã¢ãžã¥ãŒã«ã®åã¡ãœããã¯ããã®ãã³ãã©ãŒã§ã©ãããããŸãã ããšãã°ããŠã§ããµã€ãã®ååšã確èªããïŒ
public bool WebSiteExists(string name, CancellationToken token) { return ConnectAndGetValue(() => { Site site = _server.Sites[name]; return site != null; }, token); } private TValue ConnectAndGetValue<TValue>(Func<TValue> func, CancellationToken token) { TValue result = default(TValue); ConnectAndProcess(() => { result = func(); }, token); return result; }
æ¯åãµãŒããŒã«åæ¥ç¶ããã®ã¯ãªãã§ããïŒ
ãŸãããã®ã¢ãžã¥ãŒã«ãäœæãããã·ã¹ãã ã¯èªç±ã«æ§æã§ããŸãã ãããã£ãŠãã¢ãžã¥ãŒã«ã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãã©ã®ã¡ãœããã§ãã©ã®é åºã§ãã©ã®ãããã®æéå¿ èŠã«ãªãããäºåã«ããããŸããïŒMWAConnectorãšåŒã³ãŸãããïŒã
次ã«ãå¥ã®ã¹ã¬ãããã³ãã¯ã¿ãå¿ èŠãšããå ŽåããããŸãã ãããŠã1ã€ã®ã³ãã¯ã¿ã®æ¥ç¶ãéããŠããå Žåã2çªç®ã®ã³ãã¯ã¿ã®æ¥ç¶ãèš±å¯ã§ããŸããã ããããªããšãç·šéãããã¡ã€ã«ãžã®äžŠåã¢ã¯ã»ã¹ãšã©ãŒãçºçããŸãã
ãããã®èæ ®äºé ã«åºã¥ããŠãã³ãŒãã«ã¯è€æ°ã®æäœã®MWAConnectorã¯ã©ã¹ã®1ã€ã®ã€ã³ã¹ã¿ã³ã¹ãå«ãŸããåæäœã¯åå¥ã®æ¥ç¶ã®ç¬ç«ããã³ã³ããã¹ãã§å®è¡ãããŸãã
ãã®ã¢ãããŒãã®æ¬ ç¹ã¯ãæ¥ç¶ãäœæããããã®ãªãœãŒã¹ã®ã³ã¹ãã§ãã ãããã®ã³ã¹ããç¡èŠããããšã決å®ãããŸããã ãããã¯ã¢ãžã¥ãŒã«ã®ããã«ããã¯ã§ã¯ãããŸãããæäœã®çŽæ¥å®è¡ã«ã¯ãæ¥ç¶ã®äœæãããæ°åã®ããã»ããµæéãããããŸãã
AlwaysRunningã®ã€ã³ã¹ããŒã«
ã¿ã¹ã¯ã®1ã€ã¯ãAlwaysRunningãã©ã°ã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ããŒã«ãäœæããããšã§ããã Microsoft.Web.Administration 7.0.0.0ã©ã€ãã©ãªã®ApplicationPoolã¯ã©ã¹ã®ããããã£ã«ã¯ãAutoStartãEnable32BitAppOnWin64ãManagedRuntimeVersionãQueueLengthããããããããŸãã ãã ããRunningModeã¯ãããŸããã ãã®ããããã£ã¯ããŒãžã§ã³7.5.0.0ã®ãã«ãã«ãããŸãããäžèšã®ããã«ããã®ããŒãžã§ã³ã¯IIS Expressã§ã®ã¿æ©èœããŸã ã
åé¡ã®è§£æ±ºçããããŸããã ããã¯æ¬¡ã®ããã«è¡ãããŸãã
ApplicationPool pool = _server.ApplicationPools.Add(name); //some code to set pool properties if (alwaysRunning) { pool["startMode"] = "AlwaysRunning"; }
å€æŽãä¿åããã«ã¯ãCommitChangesïŒïŒã¡ãœãããåŒã³åºãå¿ èŠããããŸãã
_server.CommitChanges();
PreloadEnabledãã€ã³ã¹ããŒã«ãã
ç§ãééããå¥ã®åé¡ã¯ãWebã¢ããªã±ãŒã·ã§ã³ãšãµã€ãã«PreloadEnabledãã©ã°ãèšå®ããããã®çµã¿èŸŒã¿ããããã£ã®æ¬ åŠã§ããã ãã®ãã©ã°ã¯ãåèµ·ååŸã®ãµã€ãã®åæããŒãæéãççž®ããŸãã ãµã€ããé·æéãŠã©ãŒã ã¢ããããŠãããšãã«åœ¹ç«ã¡ãŸãã ãããŠã顧客ãå±éãããµã€ãã®äžéšã¯ãŸãã«ããã§ãã
解決çãšããŠããµã€ãã®Webã¢ããªã±ãŒã·ã§ã³ãäœæããã³ãŒããã©ã°ã¡ã³ããæäŸããŸãã
Site site = _server.Sites[siteName]; string path = string.Format("/{0}", applicationName); Application app = site.Applications.Add(path, physicalPath); app.ApplicationPoolName = applicationPoolName; if (preload) app.SetAttributeValue("preloadEnabled", true); _server.CommitChanges();
Webã¢ããªã±ãŒã·ã§ã³ã®ååã¯ã/ãã§å§ãŸãå¿ èŠãããããšã«æ³šæããŠãã ããã ãããå¿ èŠãªçç±ã¯ ããããªããšãã¢ããªã±ãŒã·ã§ã³ã®ååŸãäœæããŸãã¯åé€ã®æ¹æ³ã§ãšã©ãŒãçºçããŸãã
Webã¢ããªã±ãŒã·ã§ã³ãšããŠãµã€ãã®èšå®ãå€æŽãã
ãµã€ãèªäœã®ã¢ããªã±ãŒã·ã§ã³ããŒã«ãå€æŽããããšãå¿ èŠã«ãªãå ŽåããããŸãã åé¡ã¯ãSiteã¯ã©ã¹ã«ãã®ããããã£ããªãããšã§ãã Applicationã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§ã®ã¿èŠã€ããããšãã§ããŸãã
解決çã¯ããµã€ãã®Webã¢ããªã±ãŒã·ã§ã³ãååŸããããšã§ãã
Site site = _server.Sites[siteName]; Application app = site.Applications["/"];
ãµã€ããåé€
ãµã€ãã®åé€ã¯ç°¡åãªã¿ã¹ã¯ã®ããã«æãã_server.Sites.RemoveïŒsiteïŒãåŒã³åºãã ãã§ãã ãã ããæè¿ãhttpsãã€ã³ãã£ã³ã°ãæã€ãµã€ããåé€ãããšãã«åé¡ãçºçããŸããã å®éã«ã¯ãMicrosoft.Web.Administrationããµã€ããåé€ãããšããã€ã³ãã£ã³ã°ã«é¢ããæ å ±ãåé€ãããŸããããã¯è«ççã§ãã åæã«ãã©ã€ãã©ãªã¯IPïŒããŒãïŒSSLæºæ ã«é¢ããã·ã¹ãã kofigã®ãšã³ããªãåé€ããŸãã ãããã£ãŠãåã蚌ææžã䜿çšãããã€ã³ãã£ã³ã°ãè€æ°ã®ãµã€ãã«ããå Žåããããã®ãµã€ãã®ãããããåé€ãããšãä»ã®ãã¹ãŠã®ãµã€ãã¯ãã€ã³ãã£ã³ã°ãšèšŒææžã®ãã€ã³ãã£ã³ã°ã倱ããŸãã
ææ°ã®Microsoft.Web.Administrationã©ã€ãã©ãªã«ã¯ãã·ã¹ãã æ§æããã¬ã³ãŒããåé€ããå¿ èŠãããããšã瀺ã2çªç®ã®ãã©ã¡ãŒã¿ãŒãåãåããã€ã³ãã£ã³ã°ãåé€ããã¡ãœãããå«ãŸããŠããŸãã ãããã£ãŠãåé¡ã®è§£æ±ºçã¯æ¬¡ã®ãšããã§ãã
Site site = _server.Sites[name]; if (site == null) return; var bindings = site.Bindings.ToList(); foreach (Binding binding in bindings) { site.Bindings.Remove(binding, true); } _server.Sites.Remove(site); _server.CommitChanges();
ãããã«
çŸåšããã®ã¢ãžã¥ãŒã«ã¯ã¿ã¹ã¯ãæ£åžžã«åŠçããæ¬çªç°å¢ã§åäœããŸãã ããã«ãããæ°åã®ãµã€ããWebã¢ããªã±ãŒã·ã§ã³ãããŒã«ãä»®æ³ãã£ã¬ã¯ããªãæ¯é±äœæãããŸãã
ã¢ãžã¥ãŒã«ã®äœæ¥äžã«ééããäž»ãªåé¡ãšãèŠã€ãã解決çãæããŸããã ãã®è³æã誰ãã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã 誰ãã質åãææ¡ãããã°ãå°ããŠãã ãã-ç§ã¯çããããšããŸãã