Application Initialization の設定を Web.config には書かずに、Web.Release.config に書く場合にはどうしたらいいか?ということで、下記のような感じで Web.config には何も書かずに、Web.Release.config の applicationInitialization に xdt:Transform=”Insert” を付加すればいいですね。
[ Web.config ]
<?xml version="1.0" encoding="utf-8"?> <!-- ASP.NET アプリケーションを構成する方法の詳細については、 http://go.microsoft.com/fwlink/?LinkId=169433 を参照してください --> <configuration> <system.diagnostics> <trace> <listeners> <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> <filter type="" /> </add> </listeners> </trace> </system.diagnostics> <appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <httpRuntime targetFramework="4.5" /> <compilation debug="true" targetFramework="4.5" /> <pages> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> </configuration>
[ Web.Release.config ]
<?xml version="1.0" encoding="utf-8"?> <!-- web.config 変換の使用方法の詳細については、http://go.microsoft.com/fwlink/?LinkId=125889 を参照してください --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <!-- 次の例では、"MyDB" という値を持つ "name" 属性が "Match" ロケーターで 見つかった場合にのみ、"SetAttributes" 変換によって "connectionString" の 値が "ReleaseSQLServer" を使用するように変更されます。 <connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> --> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> <!-- 次の例では、Web.config ファイルの <customErrors> セクション全体が "Replace" 変換によって置き換えられます。 <system.web> ノードには customErrors セクションが 1 つしかないため、 "xdt:Locator" 属性を使用する必要はありません。 <customErrors defaultRedirect="GenericError.htm" mode="RemoteOnly" xdt:Transform="Replace"> <error statusCode="500" redirect="InternalError.htm"/> </customErrors> --> </system.web> <system.webServer> <applicationInitialization skipManagedModules="true" remapManagedRequestsTo="warmup.html" xdt:Transform="Insert"> <add initializationPage="/" /> </applicationInitialization> </system.webServer> </configuration>
Web.config に書くと、Windows Azure のコンピューティングエミュレーター で、下図のように IIS Express Worker Process が止まっちゃうので。
参考: Visual Studio を使用する Web アプリケーション プロジェクト配置の Web.config 変換構文