How do I set a custom error URL in IIS7.5 using WiX
-
29-10-2019 - |
Question
My first question so please be kind. I am having problems with my installer here is the error from the installer log.
MSI (s) (4C:64) [14:56:14:086]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI6E35.tmp, Entrypoint: WriteIIS7ConfigChanges
CustomAction WriteIIS7ConfigChanges returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 14:56:15: InstallFinalize. Return value 3.
The installer quits with an error and rolls back. Through trial and error I have found the problem with the IIS configuration and have narrowed it down to the setup of the custom error page (example below)
<iis:WebSite Id="myWebService1" Description="myWebService" AutoStart="yes" StartOnInstall="yes" ConfigureIfExists="yes" Directory="WEBAPPDIR" ConnectionTimeout="360" >
<iis:WebAddress Id="myWebService_Bindings" IP="*" Port="9992" />
<iis:WebApplication Id="myWebService" Name="myWebService" WebAppPool="myWebService_Pool" ScriptTimeout="360" />
<iis:WebDirProperties Id="myWebService_Properties" AnonymousAccess="yes" WindowsAuthentication="no" DefaultDocuments="Default.ashx" Read="yes" Execute="yes" Script="yes" />
<iis:WebVirtualDir Id="myWebService_Download" Alias="download" Directory="FILEDOWNLOADDIR">
<iis:WebError ErrorCode="404" URL="/dostuff.ashx" SubCode="0"/>
</iis:WebVirtualDir>
</iis:WebSite>
I think there might be an issue overwriting the default custom error pages as they are inherited although there seems to be no such problem in IIS6. I would expect the default behaviour of WiX would be to just overwrite what was already there but does not seem to be the case. I have also tried to get around this by copying a web.config with the necessary xml for the custom error to the download folder but I also get a conflict in IIS when I try to view the "Error pages" list.
I would greatly appreciate some help with this.
Solution 2
So to get around this issue I needed to create custom action and programmatically add the HttpError. I have included a method below that does it. I initially struggled to get this working because I didn't remove the existing inherited error code before adding my own one
private static void ConfigureHTTPError(long _ErrorCode, string _URL, string _SubCode, System.DirectoryServices.DirectoryEntry VDir)
{
string searcherr = _ErrorCode.ToString() + "," + _SubCode;
string customerr = searcherr + ",URL," + _URL;
for (var i = 0; i < VDir.Properties["HttpErrors"].Count; i++)
{
if (VDir.Properties["HttpErrors"][i].ToString().IndexOf(searcherr) == 0)
{
//must remove the existing error code first
VDir.Properties["HttpErrors"].RemoveAt(i);
VDir.CommitChanges();
VDir.Properties["HttpErrors"].Add(customerr);
VDir.CommitChanges();
}
}
}
Hope this helps if you come across the same issue. I have more code around this so if you need help just ask.
OTHER TIPS
I was running into the exact same thing. I found an answer for it here.
It's handled in the web.config file like this:
<system.webServer>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="filePath.aspx" responseMode="ExecuteURL"/>
</httpErrors>