Running ASP.NET 4.6 application inside a docker container - Site always 404s

0

I've been attempting to get an ASP.NET 4.6 application to run inside a Windows Docker container and while getting IIS to run with the default website was fairly simple, trying to get my actual application to run is proving to be difficult. Whenever I attempt to load my application it returns a 404 file not found.

Some background: The application I'm trying to run has to be installed under 'Default Web Site' with both the application and a SharedContent application installed under IIS, where the SharedContent is also a sub-application under the main application.

This results in 3 calls install the application under IIS:

RUN ["powershell", "New-WebApplication -Name MvcCompaniesV2 -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/MvcCompaniesV2 -ApplicationPool DefaultAppPool"]
RUN ["powershell", "New-WebApplication -Name SharedContent -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/SharedContent -ApplicationPool DefaultAppPool"]
RUN ["powershell", "New-WebApplication -Name MvcCompaniesV2/SharedContent -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/SharedContent -ApplicationPool DefaultAppPool"]

After fiddling around for about a full day I'm confused. I managed to install IIS WebManagement and can connect to my container using the IIS Manager and I can see my websites are properly configured with one exception: the connection strings and rewrite rules from the web.config aren't visible from the IIS settings, like it can't access the config file. IIS runs under the IIS APPPOOL\DefaultAppPool user and the wwwroot folder has IIS_IUSRS added to its ACL(as by default).

This is my docker file:

FROM microsoft/aspnet:4.7.2-windowsservercore-1803

EXPOSE 80
EXPOSE 8172

EXPOSE 4020 4021 4022 4023

# WebManagement stuff
RUN ["powershell.exe", "Install-WindowsFeature NET-Framework-45-ASPNET"]  
RUN ["powershell.exe", "Install-WindowsFeature Web-Asp-Net45"]
RUN ["powershell.exe", "Install-WindowsFeature web-mgmt-service"]

RUN ["powershell.exe", "Set-ItemProperty -Path 'HKLM:/SOFTWARE/Microsoft/WebManagement/Server' -Name 'EnableRemoteManagement' -Value 1"]
RUN ["powershell.exe", "set-service -Name WMSVC -StartupType Automatic"]
RUN ["powershell", "start-service WMSVC"]
RUN ["powershell", "net user patrick l0lp@ssw0rd /add"]
RUN ["powershell", "net localgroup administrators patrick /add"]

# Rewrite module
ADD https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi rewrite_amd64.msi
RUN ["powershell" , "Start-Process msiexec.exe -ArgumentList '/i', 'rewrite_amd64.msi', '/quiet', '/norestart' -NoNewWindow -Wait"]

# Remote debugger
RUN Invoke-WebRequest -OutFile c:\rtools_setup_x64.exe -Uri https://aka.ms/vs/15/release/RemoteTools.amd64ret.enu.exe;
RUN & 'c:\rtools_setup_x64.exe' /install /quiet

ADD bin C:/inetpub/wwwroot/

RUN ["powershell", "New-WebApplication -Name MvcCompaniesV2 -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/MvcCompaniesV2 -ApplicationPool DefaultAppPool"]
RUN ["powershell", "New-WebApplication -Name SharedContent -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/SharedContent -ApplicationPool DefaultAppPool"]
RUN ["powershell", "New-WebApplication -Name MvcCompaniesV2/SharedContent -Site 'Default Web Site' -PhysicalPath C:/inetpub/wwwroot/SharedContent -ApplicationPool DefaultAppPool"]

# ErrorPages mode to off
RUN ["powershell", "Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT' -filter 'system.web/customErrors' -name 'mode' -value 'Off'"]
RUN ["powershell", "Set-WebConfigurationProperty -filter 'system.webServer/httpErrors' -name 'errorMode' -value 'Detailed'"]
RUN ["Powershell", "Set-WebConfigurationProperty -pspath 'IIS:\Sites\Default Web Site\MvcCompaniesV2' -filter 'system.webServer/httpErrors' -name 'errorMode' -value 'Detailed'"]

ENTRYPOINT ["powershell", ""]

Any ideas on how I can troubleshoot this? As can be seen, I changed the errorPages mode for both IIS and .NET to detailed but whenever I open MvcCompaniesV2, I still get the very limited error page (https://imgur.com/a/jvj9r7f). I'm kind of out of ideas what I can try to troubleshoot this.

I tried a sample asp.net page(which runs directly under 'Default Web Site' and that works fine out of the box').

EDIT: When I attach the remote debugger to my project it breaks with an ArgumentException inside the framework code:

System.ArgumentException
  HResult=0x80070057
  Message=The parameter 'C:/inetpub/wwwroot/MvcCompaniesV2\' is invalid.
Parameter name: C:/inetpub/wwwroot/MvcCompaniesV2\
asp.net
powershell
docker
iis
asked on Stack Overflow Feb 22, 2019 by Toolmaker • edited Feb 22, 2019 by Toolmaker

1 Answer

2

I fixed this problem by fixing the malformed 'PhysicalPath's from the New-WebApplication calls. The debugger's ArgumentException gave it away, IIS doesn't tolerate / in the paths. After updating them to C:\\inetpub\\wwwroot\\MvcCompaniesV2 the problem went away.

answered on Stack Overflow Feb 22, 2019 by Toolmaker

User contributions licensed under CC BY-SA 3.0