I configured IIS ApplicationInitialization as recommended in the documentation add initializationPage='/warm-up' - asp.net-core

I configured IIS ApplicationInitialization as recommended in the documentation
add initializationPage='/warm-up'.
I implemented a /warm-up endpoint on my app deploy it to both staging and production slots.
When the app starts/restarts/swap the endpoint is NOT called because I can't see it in the logs.
When I hit the endpoint manually, it works fine!
What I'm trying to achieve is:
When I start/restart/swap my app
I want a page (/warm-up) to be called in order to preload the app
So the first call from a real client doesn't have to suffer from the app loading time
Currently, I implemented a service that runs when the app starts (IStartupfilter)
But the app, hence the filter, is not running before a first request hits the server!
So I want to hit the server instance as soon as possible with appInit
We have more than 5 instances at some time of the day

initializationPage is an IIS thing, it will not help you start up the ASP.NET Core application before the first request hits.
Instead, what you will need to do is configure the Application Initialization Module for ASP.NET Core. According to this documentation, you will need to enable the IIS Application Initialization module (which you probably already did if you could configure the initializationPage) and then modify the generated web.config to include the applicationInitialization node to the webServer section:
<?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=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<applicationInitialization doAppInitAfterRestart="true" />
</system.webServer>
</location>
</configuration>
This should start the ASP.NET Core application as soon as the IIS website starts, so there should be no delay. You will not need an initialization page then and can just initialize the ASP.NET Core application as the host starts.

Related

how to restart Hangfire server after reboot server IIS 8.5

I created a webapp with blazor serverside with a scheduler in my app using Hangfire. It's hosted in a IIS 8.5 on windows server 2012.
I already did all the settings to make sure my blazor app dont stop and dont recycle (idle=0,startmode,Regular Time Interval...) so the sheduler is always running. And all work good.
But if there is any server reboot, i need to restart my Hangfire server to restart the sheduler inside the app (just with single ping of the url in a browser)...
Like we can see on the screen, the hangfire server dont start until i ping my blazor's URL in a browser...
So you implemented all steps outlined in the hangfire documentation including preload and applicationInitialization?
Step 5 is persisted in the web.config of your application. To make sure it is not overwritten on deployment, one can put a web.config with the respective configuration under source control.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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" />
<!-- Add this node to web.config -->
<applicationInitialization doAppInitAfterRestart="true">
<!-- Only needed when website contains multiple child apps -->
<add initializationPage='/hangfire',hostname='' />
<applicationInitialization />
</system.webServer>
</configuration>
Finally, if you use the app_offline.htm during deployment either directly or indirectly through the Azure DevOps Pipelines deploy task, then after the app_offline.htm is removed, only the next request restarts the app. In that case you need to fire a warm-up request manually. You can use a more elaborate warm-up script or this one-liner in your deployment pipeline.
curl https://my-page.com/
I think this is primarily an IIS thing, and what you want is to set the Application Pool in IIS to AlwaysRunning, so instead of starting up the worker process on the first web request it starts the worker process as soon as IIS starts.
See this SF answer

IIS cannot open web.config - The requested page cannot be accessed because the related configuration data for the page is invalid

I'm trying to deploy new asp.net core 5 (5.0.100-rc.1.20452.10) app to IIS on Win 10 and Windows Server 2019.
I've deployed the app using Visual Studio to Default Web Site with ApplicationPoolIdentity and granted full access permission to both "IIS_IUSRS" and "Everyone".
I'm still getting:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
When I try to open the config in IIS Manager I get "Data is invalid" error:
The webconfig looks pretty normal:
<?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=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
I think I've installed all IIS Features:
I had the same issue, while deploying net core 6 application.
I gave the IUSR and IIS_IUSR permissions.
I installed the URL rewrite extension.
The thing finally saved me was I checked for if net core hosting was installed on my system, we can verify in system registry under:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Updates.NET Core path
like screenshot below.
And I fixed it after downloading the hosting module:
.Net hosting bundle
And now the settings and application works fine.

.NET Core 2.2 Publishing problems

I have a web hosting which supports ASP.NET Core 2.2. I tried to publish my own asp.net core 2.2 project in it and it worked with just design. And then I added Identity in the project and I added the same database in the host (exported and imported db which created with migrations). I changed the database connection as well, but when I'm trying to publish the same project it gives me this error :
HTTP Error 502.5 - Process Failure
Common causes of this issue:
The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=808681
Here is my connection string :
"ConnectionStrings": {
"IdentityConnection": "Data Source=.\MSSQLSERVER2016;Database=ChatIdentity;Integrated Security=False;User ID=halitkal;Password=*;Connect Timeout=15;Encrypt=False;Packet Size=4096"
},
Here is my webconfig file :
<?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=".\ChatSite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 028aa0e3-c5ef-4f5c-87ac-e8de39c5ca44-->
Turn on the stdout logs by changing the next line in the web.config
aspNetCore processPath="dotnet" arguments=".\ChatSite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
Don't forget create a folder named logs in the same directory that you have your dll files.
Then reboot the application (Application pool if you´re hosting in IIS) then make an http request and then check for generated log, that should give to you the detail about the error.
If that not works, make sure you have the right runtime installed.

Setting requestTimeout in web.config of an ASP.NET Core Azure Web App via Application Settings

I have a web.config that looks like so, and is added as a link to a number of applications in my solution:
<configuration>
<!-- For more info to customize the asp.net core module see https://go.microsoft.com/fwlink/?linkid=838655 -->
<system.webServer>
<!-- As connection proxy request contains double escape sequence, we need to enable it. background Azure ARM Apis are enabled it. -->
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout"/>
</system.webServer>
</configuration>
One of the services has potential for long running single requests, and so I want to increase the IIS request timeout for that service, which can be achieved by adding to the aspNetCore configuration like so:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" requestTimeout="00:10:00"/>
However, given this web.config is otherwise shared and I don't want to alter the behaviour of my other apps, I'd like configure this via an application setting from my arm templates.
When I attempt something like the following, I get an error that %REQUEST_TIMEOUT% is not a valid time, and deploying fails to startup the webapp.
How can I enable app settings to insert into the request timeout field?
Azure App Service doesn't allow increase requestTimeout, the limit is 230 seconds - see Why does my request time out after 230 seconds?.
I would recommend looking at the Polling (link2) - it is the standard REST-pattern to process long running op.
Other resources:
How can increase Azure App Service 230 sec request time out
Increase azure web app request timeout
If you are using Azure DevOps, some options during deployment:
"XML variable substitution" can be enabled during deployment if you are using Azure App Service deploy task.
Add powershell task to change the request timeout with the value from a pipeline variable.
Note: If the requestTimeout is set to say 10 mins in web.config, the request will continue to run to completion even after 230 seconds. But the client will be terminated by the app service at 230 seconds and will receive an error.

How to resolve Internal Server Error 500 on .Net Core 2.1.1 on IIS 8.5

I've read many similar issues but none of the resolutions solved my problem. So, here is my case.
I have a NET Core 2.1.1 app that runs beautifully within VS2017 and when published to my desktop running Win10 Pro and IIS10, i.e. running it outside of VS2017. But, when I deploy the app to a remote server Win2012 R2 with IIS8.5, I get the following issues with it.
I have followed different pages on deploying net core apps like this one.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.1
When attempting to reach the site I get error 500 Internal Server Error.
IIS manager complains about the generated web.config when clicking on any of the site's settings e.g. Net authorization, Net Error pages etc...
Even when setting the stdoutLogEnabled to true, I don't get any log files. I even tried adding custom details flags in the web.config yet still nothing changed.
This is the generated web.config, and I hope someone points me in the right direction.
Thanks.
<?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=".\eSignWebMVC.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 72897161-bbbb-4f20-a12c-7f33922ea6bc-->
So I finally got this to work and I HAD to install the latest bundle v2.2.2 even though my app is targetting Net Core 2.1.1, but Microsoft's horrible technology still didn't make the app to run with the 2.1.1. bundle. Total waste of time and effort on such a stupid thing!!
What's the meaning of still providing the prior bundles if none of them does anything?