diff --git a/src/Installers/Windows/AspNetCoreModule-Setup/ANCMIISExpressV2/ancm_iis_expressv2.wxs b/src/Installers/Windows/AspNetCoreModule-Setup/ANCMIISExpressV2/ancm_iis_expressv2.wxs index 49bae9932b..279bb8688a 100644 --- a/src/Installers/Windows/AspNetCoreModule-Setup/ANCMIISExpressV2/ancm_iis_expressv2.wxs +++ b/src/Installers/Windows/AspNetCoreModule-Setup/ANCMIISExpressV2/ancm_iis_expressv2.wxs @@ -366,66 +366,25 @@ Value=""[IISEXPRESS_INSTALL_PATH]appcmd.exe" set config -section:system.webServer/httpCompression /+"dynamicTypes.[\[]mimeType='text/event-stream',enabled='FALSE'[\]]" /apphostconfig:"[IISEXPRESS_APPHOST_CONFIG_TMP]""/> - - - - + Value="[IISEXPRESS_APPHOST_CONFIG]"/> + + + + - - - - + Property="CA_REMOVE_CONFIGSECTION" + Value="[IISEXPRESS_APPHOST_CONFIG]"/> + + + + - - - - - - + Property="CA_ADD_CONFIGSECTION32" + Value="[IISEXPRESS_APPHOST_CONFIG32]"/> + + + + - - - - + Value="[IISEXPRESS_APPHOST_CONFIG32]"/> + + + + @@ -600,7 +516,9 @@ - + + + @@ -610,6 +528,8 @@ + + @@ -640,7 +560,9 @@ - + + + @@ -650,6 +572,8 @@ + + diff --git a/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.cpp b/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.cpp index 48d826f720..7727eeed5c 100644 --- a/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.cpp +++ b/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.cpp @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #include +#include +#include DECLARE_DEBUG_PRINT_OBJECT( "proxyCA.dll" ); @@ -40,6 +42,138 @@ struct COMPRESSION_MIME_TYPE COMPRESSION_MIME_TYPE gMimeTypes[] = { { L"text/event-stream", FALSE} }; +#define _HR_RET(hr) __pragma(warning(push)) \ + __pragma(warning(disable:26498)) /*disable constexpr warning */ \ + const HRESULT __hrRet = hr; \ + __pragma(warning(pop)) + +#define _GOTO_FINISHED() __pragma(warning(push)) \ + __pragma(warning(disable:26438)) /*disable avoid goto warning*/ \ + goto Finished \ + __pragma(warning(pop)) + +#define RETURN_IF_FAILED(hrr) do { _HR_RET(hrr); if (FAILED(__hrRet)) { hr = __hrRet; IISLogWrite(SETUP_LOG_SEVERITY_INFORMATION, L"Exiting hr=0x%x", hr); return hr; }} while (0, 0) + +// Modifies the configSections to include the aspNetCore section +UINT +WINAPI +AddConfigSection( + IN MSIHANDLE handle +) +{ + HRESULT hr; + CComPtr pXMLDoc; + VARIANT_BOOL variantResult; + IXMLDOMNode* webServerNode; + IXMLDOMNode* aspNetCoreNode; + IXMLDOMNode* tempNode; + IXMLDOMElement* element; + STRU customActionData; + + CComBSTR selectLanguage = SysAllocString(L"SelectionLanguage"); + CComBSTR xPath = SysAllocString(L"XPath"); + CComBSTR webServerPath = SysAllocString(L"//configuration/configSections/sectionGroup[@name=\"system.webServer\"]"); + CComBSTR aspNetCorePath = SysAllocString(L"//configuration/configSections/sectionGroup[@name=\"system.webServer\"]/section[@name=\"aspNetCore\"]"); + CComBSTR section = SysAllocString(L"section"); + CComBSTR name = SysAllocString(L"name"); + CComBSTR aspNetCore = SysAllocString(L"aspNetCore"); + CComBSTR overrideMode = SysAllocString(L"overrideModeDefault"); + CComBSTR allow = SysAllocString(L"Allow"); + + RETURN_IF_FAILED(CoInitialize(NULL)); + + hr = MsiUtilGetProperty(handle, TEXT("CustomActionData"), &customActionData); + + RETURN_IF_FAILED(hr = pXMLDoc.CoCreateInstance(__uuidof(DOMDocument60))); + + RETURN_IF_FAILED(hr = pXMLDoc->put_async(false)); + + RETURN_IF_FAILED(hr = pXMLDoc->load(CComVariant(customActionData.QueryStr()), &variantResult)); + + if (variantResult == VARIANT_FALSE) + { + return ERROR_SUCCESS; + } + + RETURN_IF_FAILED(hr = pXMLDoc->setProperty(selectLanguage, CComVariant(xPath))); + + RETURN_IF_FAILED(hr = pXMLDoc->selectSingleNode(webServerPath, &webServerNode)); + + RETURN_IF_FAILED(hr = pXMLDoc->selectSingleNode(aspNetCorePath, &aspNetCoreNode)); + + if (aspNetCoreNode == NULL) + { + RETURN_IF_FAILED(hr = pXMLDoc->createElement(section, &element)); + + RETURN_IF_FAILED(hr = element->setAttribute(name, CComVariant(aspNetCore))); + + RETURN_IF_FAILED(hr = element->setAttribute(overrideMode, CComVariant(allow))); + + RETURN_IF_FAILED(hr = webServerNode->appendChild(element, &tempNode)); + + RETURN_IF_FAILED(hr = pXMLDoc->save(CComVariant(customActionData.QueryStr()))); + } + + return ERROR_SUCCESS; +} + +// Modifies the configSections to remove the aspNetCore section +UINT +WINAPI +RemoveConfigSection( + IN MSIHANDLE handle +) +{ + HRESULT hr; + CComPtr pXMLDoc; + VARIANT_BOOL variantResult; + IXMLDOMNode* webServerNode; + IXMLDOMNode* aspNetCoreNode; + IXMLDOMNode* tempNode; + IXMLDOMElement* element; + STRU customActionData; + + CComBSTR selectLanguage = SysAllocString(L"SelectionLanguage"); + CComBSTR xPath = SysAllocString(L"XPath"); + CComBSTR webServerPath = SysAllocString(L"//configuration/configSections/sectionGroup[@name=\"system.webServer\"]"); + CComBSTR aspNetCorePath = SysAllocString(L"//configuration/configSections/sectionGroup[@name=\"system.webServer\"]/section[@name=\"aspNetCore\"]"); + CComBSTR section = SysAllocString(L"section"); + CComBSTR name = SysAllocString(L"name"); + CComBSTR aspNetCore = SysAllocString(L"aspNetCore"); + CComBSTR overrideMode = SysAllocString(L"overrideModeDefault"); + CComBSTR allow = SysAllocString(L"Allow"); + + RETURN_IF_FAILED(CoInitialize(NULL)); + + hr = MsiUtilGetProperty(handle, TEXT("CustomActionData"), &customActionData); + + RETURN_IF_FAILED(hr = pXMLDoc.CoCreateInstance(__uuidof(DOMDocument60))); + + RETURN_IF_FAILED(hr = pXMLDoc->put_async(false)); + + RETURN_IF_FAILED(hr = pXMLDoc->load(CComVariant(customActionData.QueryStr()), &variantResult)); + + if (variantResult == VARIANT_FALSE) + { + return ERROR_SUCCESS; + } + + RETURN_IF_FAILED(hr = pXMLDoc->setProperty(selectLanguage, CComVariant(xPath))); + + RETURN_IF_FAILED(hr = pXMLDoc->selectSingleNode(webServerPath, &webServerNode)); + + RETURN_IF_FAILED(hr = pXMLDoc->selectSingleNode(aspNetCorePath, &aspNetCoreNode)); + + if (aspNetCoreNode != NULL) + { + RETURN_IF_FAILED(webServerNode->removeChild(aspNetCoreNode, &tempNode)); + + RETURN_IF_FAILED(hr = pXMLDoc->save(CComVariant(customActionData.QueryStr()))); + } + + return ERROR_SUCCESS; +} + UINT WINAPI RegisterANCMCompressionCA( diff --git a/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.def b/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.def index 3518cde35f..ed516a4392 100644 --- a/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.def +++ b/src/Installers/Windows/AspNetCoreModule-Setup/CustomAction/aspnetcoreCA.def @@ -18,6 +18,8 @@ EXPORTS ExecuteCleanUpWindowsHotfixCA ScheduleRebootIfRequiredCA + AddConfigSection + RemoveConfigSection RegisterANCMCompressionCA CheckForServicesRunningCA diff --git a/src/Installers/Windows/UpgradeLog.htm b/src/Installers/Windows/UpgradeLog.htm new file mode 100644 index 0000000000..f327ebd6ec Binary files /dev/null and b/src/Installers/Windows/UpgradeLog.htm differ