Run go web application on IIS - iis

Is there a way to run Go web application on IIS?
I found a setting for azure but its not working on my dev machine
this is a web config for azure :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe"
arguments="run d:\home\site\wwwroot\server.go"
startupTimeLimit="60">
<environmentVariables>
<environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

Your local IIS does not work simply because you need to install a separate component, called HttpPlatformHandler module,
https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/
http://www.iis.net/downloads/microsoft/httpplatformhandler
Reverse proxy or FastCGI were the older approaches which are no longer necessary with this new approach.

HttpPlatformHandler module doesn't work for me. I found this post by Sutean Rutjanalard on Medium very helpful, which use ASP.NET Core Module instead.
Basically, you need to create Application pool with "No Managed Code" as you do with a .net core app. And the following is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\YourGoApp.exe" />
</system.webServer>
</configuration>

Related

Why Azure Web App not starting when I add maxAllowedContentLength in web.config?

I'm developing ASP.NET 7 WebApi app which is hosted on Azure Web App. I need to transfer large files. Many resources show that I need to add node in web.config, but when I add, my azure web app won't start.
My web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false"
stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647 " />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 46edd0a7-6184-47ed-a0e9-d3be7fee8b41-->
And this message is shown when I try to open web app.
As in title: Why it's not working? Do I missed some step?

ASP.NET Core 3 - Is there a way to add Module section to produced Web Config File

Like said in the title i'm publishing an ASP.NET Core 3 API to IIS. When i publish that API the system create a web config file in the deploy directory containing that :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\xxxxx.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: daddb75b-3c54-4970-8945-8404ade81fbc-->
Everything is ok but what's i want to do is to add the three lines below in the System.webServer section in order to cover the issue described in this link : https://fantinel.dev/net-core-api-method-not-allowed-on-put-and-delete-requests/
Extract for explanations :
What happens is that, when published, .NET Core enables the
WebDAVModule, which disables PUT and DELETE requests by default.
So to get PUT and DELETE verbs we have to disable this WebDAVModule with this lines :
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
Is there a way to automatize the include of this lines to the produced/published web.config ? In the VS solution i don't see any Web.Config file or option to drive the output of deploy.
Thanks you all for your advices.
I just found out that when you add a web.config file yourself, the publishing wizard combines the normally generated web.config with the file you define yourself. Eg:
No web.config ==> Produces following web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7b031640-46da-4eac-b60c-740bd3659fce-->
Following web.config in the root of your ASP.NET Core project
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</location>
</configuration>
Produces following web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
So it seems that the ASP.NET Core deployment is combining both xml's. I'm using ASP.NET Core 3.1.

Is it possible to have 2 ASP.NET Core sites in one Web App?

Is it possible to have 2 ASP.NET Core Web API apps inside the one App Service?
I understand that it would be better to have the 2 sites in separate App Services, but our use case is a bit unique.
We're trying to add the 2nd site for the purposes of using the applicationInitialization feature to introduce a delay between our app starting and the instance being given to the App Service load balancer.
I could go into a lot more detail on this, but what I desire for now is to bolt-on an additional web site that the applicationInitialization can call to delay the startup process.
I've tried:
Folder structure:
/mySite
/mySite2
web.config
Folder structure:
/mySite2
mySite.dll
web.config
With respective web.Configs looking like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="mySite" inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\mysite\mySite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
<location path="mySite2" inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\mySite2\mySite2.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
and
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\mySite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
<location path="mySite2" inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\mySite2\mySite2.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
YES. It is possible, you can have two applications on a single web app with a virtual directory.
From docs:
Virtual Directories are supported for Azure Websites. See Configuring
Azure Websites for what you can do through the Azure Management
Portal. From the Azure Portal, click on the Website and go to
Configure, then scroll down to virtual applications and directories
(the last config section). Just enter your virtual directory and the
physical path relative to the site root and click Save.

How can I resolve 500.19 on all my application?

I create .Net Core web application, I have to download .NET Core Runtime & Hosting Bundle but when I do that all my application get this error.
Even if I uninstall it, I still have the error.
When I try to run it in the command prompt with dotnet command it works but it doesn't work on IIS 10.
UPDATE :
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\ProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>

Azure multiple sites in virtual directories

I have 3 asp.net core sites I need to deploy on the same domain (subdomains will not work with my SSL certificate).
https://my-site.com (Single page app)
https://my-site.com/api (Web api)
https://my-site.com/identity (Identity server)
When I deploy the api and identity projects, they work fine. However, when deploying the single page app, api and identity stop working.
The page cannot be displayed because an internal server error has occurred.
The error appears instantly so it's probably failing early on from startup I guess.
The single page app is working ok.
It seems the spa is interfering, I tried solutions from here to ignore the routes, but I get the same error.
I have tried the solution here to get a more descriptive error but to no avail.
Not sure where to go from here
The cause of the problem is that both the root application and the child app add the aspNetCore handler, causing the config system to blow up. You can see this by turning on Detailed error messages in the Azure Portal, and then finding the error page under D:\home\LogFiles\DetailedErrors. You'll see this error:
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'aspNetCore'
There are two approaches to solving this.
The first is to use a location tag to prevent inheritance. Specifically, change your root app's web.config from something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</configuration>
to something like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</location>
</configuration>
The second approach is to remove the <handlers> section from the sub-application to avoid the duplication (as suggested in the doc under Configuration of sub-applications):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" arguments=".\mySubApp.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</configuration>

Resources