IIS Dynamic Compression and ASP.NET Core - asp.net-core

I have an ASP.NET Core v2.2 application deployed to IIS. I'm following the recommendation of using IIS dynamic compression rather than the response compression middleware as stated in Response compression in ASP.NET Core. I used the IIS Management Tool to configure the dynamic compression in IIS and it's working as expected. However, this updates the application's web.config to include a urlCompression element.
<?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=".\xyz.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
<system.webServer>
<urlCompression doDynamicCompression="true" />
</system.webServer>
</configuration>
My issue is that the next time I publish the application the dynamic compression setting is lost and I have to go back into the IIS Management Tool to configure it again.
How do I ensure this setting is preserved after re-publishing my application and without having to go into the IIS Management Tool every time?
Is there a way to include this dynamic compression setting in the Visual Studio project so it's included in the generated web.config file?

You can create a "web.config" file in the root of your project, and the contents will be merged with the other generated content in the resulting "web.config" file after publishing.
Example project file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" />
</system.webServer>
</configuration>
Contents of "web.config" file at the published location:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="true" />
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\xxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>

Related

Net Core 5 project refuses to run

I have gone through many sites figuring out how to prepare Net Core 5 project to run in IIS. I did publishing, I have downloaded all the needed pieces (or so I think) from here:
Link
My web.config looks like this:
<?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=".\RoundTheCode.ReactSignalR.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
But when I run website like this:
http://localhost:8090/methodname I get:
Feels like I am still missing some parts of the framework. Can someone please explain what needs to be checked for that?
Thanks

HTTP Error 500.19 - Internal Server Error-0x8007000d

I encountered this error when I tried to host my asp .net core project on local iis.
I have installed the asp .net hosting bundle, checked the permissions to my web.config file but still of no use.
My web.config file is as follows:
<?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=".\SampleApp1.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: e4b7dcc7-c9c3-48c5-9a12-0a9ee0c9ac2c-->
My asp .net version is 3.1.201.
Also, usually at the error page you should see the physical path as well but in my case that's empty though I set the physical path to my web files.

"The specified CGI application encountered an error and the server terminated the process" on gearhost

Im trying to deploy a net core 2.2 web app on gearhost but im getting an error that says "The specified CGI application encountered an error and the server terminated the process."
The app works fine without problems on localhost but everytime i try to publish it to gearhost, i get that error.
Here is my web.config
<?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=".\app.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>

.Net Core AspNetCoreHostingModel what does it mean?

By this link, you can read about ASP.NET Core Module
To configure an app for in-process hosting, add the property to the app's project file with a value of InProcess (out-of-process hosting is set with OutOfProcess)
I've read several times but I don't understand what it's mean?
When I must use OutOfProcess and when InProcess?
Pros and cons these models?
What to rely on when making a decision?
Is referring to how IIS is hosting your app (web.config).
InProcess : IIS host the app (w3wp.exe or iisexpress.exe)
OutOfProcess: Kestrel host the app, IIS is a proxy to kestrel.
More details on how to configure and what to keep in mind for each one when using.
'InProcess' has significant better performance according to Microsoft.
To configure InProcess add web config with:
<?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="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
<environmentVariables />
</aspNetCore>
</system.webServer>
</location>
</configuration>
For OutOfProcess:
<?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="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables />
</aspNetCore>
</system.webServer>
</location>
</configuration>
when you will generate the build in my-api folder or plain publish to your server with:
dotnet publish -o my-api -c release
will take care if your %LAUNCHER_PATH% and %LAUNCHER_ARGS%.
What you are referring in initial question possibly is about .csproj config that dictate how app runs locally, default is InProcess

HTTP Error 500.19 - Internal Server Error (says invalid web.config, but its valid)

This is on a brand new server running windows 2016, installed the hosting bundle, set the app pool to no managed.
Here is my web.config (generated by vs, using a default, nothing changed asp.net 2.0 web app)
<?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=".\WebApplication2.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
I had not installed the hosting bundle properly.. now its installed properly it all works