IIS ASP.NET Core application not starting - c#

I have created an ASP.NET Core web api that has been tested on many PC's but when deploying to client's IIS server, the application does not start or produce any error, as checked in Application Event logs.
Running the executable directly, the application works and you can browse to the ASP.NET Core website.
I navigated to the web.config file to find the dll to run:
<?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=".\MY_API.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: c1c1b8d5-abcd-479f-9e7a-abcdefghijkl-->
running dotnet MY_API.dll produces the following:
The port is not bound to any other application, as when i run the executable, it binds to the port successfully and i can navigate to localhost:port and the api swagger interface is displayed.
The dotnet command successfully runs the application on my development PC.
I can confirm that IIS is running the same modules that i am running on my dev PC and the same .net runtime hosting bundle is installed on the server as is installed on my dev PC.
I feel that this is just a permissions issue, that the security policy perhaps is preventing me from binding ports using the dotnet command, which i have read that is what IIS uses to launch the application in the background.
My knowledge on service accounts and ApplicationPoolIdentities are very limited. What is the permissions that would prevent the application to bind the port using the dotnet command, where running the executable allows me to bind to the port? How do i change these permissions?

Related

ASP.NET Core + Framework in IIS getting HTTP 404

Ok - this is my first deployment of an ASP.NET Core app. One wrinkle to keep in mind is that I am using ASP.NET Core 2.2 and targeting Framework version 4.6.2 (not .Net Core). It all runs fine on my local machine with VS2017 and IISExpress.
I went through the procedure outlined by MS here: Host ASP.NET Core on Windows with IIS The documentation is long and complicated, but I think I covered everything. It makes one thing clear: The in-process hosting model isn't supported for ASP.NET Core apps that target the .NET Framework. So, I know I need to use Out-of-Proc.
Some other points:
I published the app to a local folder and copied it to the server without any changes.
I created the new app in the Default Web Site and gave it its own app pool - set as "No Managed Code"
Out-of-proc is the default, so I have not done any special config for this.
I have confirmed that AspNetCoreModuleV2 appears in the list of Modules.
The Result
Every page I hit I get HTTP404. I am running IE locally on the server and using a URL like: http://localhost/MyApp/Home/MyView
The application pool shows having 1 application running.
The App Event Log shows a message like: Application '/LM/W3SVC/2/ROOT/MyApp' started process '8864' successfully and process '8864' is listening on port '37706'. It shows no errors.
I have tried adding a default.htm file to the root of the app and loading the static page directly (using http://localhost/MyApp/default.htm). This gives 404. If I remove the web.config, this page will load.
I really didn't expect deploying the app to be this complicated.
Can anyone provide any guidance on how to troubleshoot or fix this problem?
Update 1: Web.config is below. I have tried with and without hostModel=... aspNetCore logs show successful startup. Nothing is added to the log with each page access attempt (seems weird)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
<remove name="BlockViewHandler" />
<add name="JavaScript" path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="CSS" path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
<aspNetCore processPath=".\My.App.Name.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables />
<handlerSettings>
<handlerSetting name="debugLevel" value="file" />
<handlerSetting name="debugFile" value="d:\Log\MyApp.log" />
</handlerSettings>
</aspNetCore>
</system.webServer>
</configuration>
<!--ProjectGuid: ee76911e-decb-48b7-bd74-36ebfbdb22b6-->
Solved! I was making use of the ASPNETCORE_ENVIRONMENT environment variable, but was unaware that the publish process does not put this in web.config. I added this to Web.config:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
and the pages now load.
The most useful diagnostics I found were at this link Troubleshoot ASP.NET Core on IIS There they recommended that I run My.App.Name.exe from the command prompt. This creates a web process and assigns it to a port and gives you all the console output. This allowed me to figure out it was actually half working and that led me to the fact that I was missing the Env Variable.
Thanks again for the suggestions...

Error trying to host an ASP.NET 2.2 Website on Plesk Onyx 17.8.11 - HTTP Error 500.0 - ANCM In-Process Handler Load Failure

I'm attempting to host a ASP.NET 2.2 Website on a interserver.com shared hosting platform. They are using Plesk Onyx version 17.8.11 as their hosting platform control panel.
I've verified the hosting is routed and setup correctly but still get the runtime error:
HTTP Error 500.0 - ANCM In-Process Handler Load Failure
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found
The in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application
ANCM could not find dotnet.
I reported the issue to customer service and they have sent me a few articles of things to try but no solution has been found. Since the error says that the key aspnet core library could not be found, they said they have "installed .NET core 2.1.10 and 2.2.2 hosting bundle" but I'm still getting the same error.
The web.config on the host (auto-generated) is:
<?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=".\BridgeSite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7bcb9c33-cd6b-4078-9742-869d5dd7bxxx -->
Any suggestions stackoverflow family?
Since this is a shared hosting platform I do not have access to fiddle around with server configurations. From what I can tell, something went wrong with the ASP.NET Core 2.2.4 runtime installation and AspNetCoreModuleV2.dll is missing/corrupt/misplaced?
After spending far to much time on this I found a couple workarounds:
Every time you publish, go to the folder on the host where the code was published, open the auto-generated web.config, under the handlers node replace "AspNetCoreModuleV2" with "AspNetCoreModule". This works, by defaulting it back to the previous package, but is crappy because it has to be done manually every time the code is published.
OR,
in the Visual Studio solution, open (or create new) publish profile under Properties > PublishProfiles. In the PropertyGroup add: <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>. This works but is a big hack and the application will not have all the performance gains of being InProcess (Default)
After testing, I found you can use one or the other, you don't have to use both.
I'm hoping this issue will resolve itself over time as the hosting service continues to update their runtimes, but for now hopefully those workarounds will help you too.
This error is documented, along with the solution:
500.0 In-Process Handler Load Failure
The worker process fails. The app doesn't start.
The ASP.NET Core Module fails to find the .NET Core CLR and find the in-process request handler (aspnetcorev2_inprocess.dll). Check that:
The app targets either the Microsoft.AspNetCore.Server.IIS NuGet package or the Microsoft.AspNetCore.App metapackage.
The version of the ASP.NET Core shared framework that the app targets is installed on the target machine.
The most likely scenario is that you've failed to installed the .NET Core runtime at all or at least failed to install the correct version thereof to match what your project is targeting.
For Asp.Net Core 2.2 MVC.
1. Create web.config at the root on the Project.
2. Past this configuration:
<?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=".\logs\stdout"
hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
I was having the same issue with Interserver.com.
Support was able to solve the problem by switching my application pool to 64 bit. From what I have read in regards to other Plesk hosting providers is that by default the scripts that create your virtual machine by default create the application pool in 32 bit. I'm guessing that AspNetCoreModuleV2 requires 64 bit, but that is just a guess. Happy that my site is running in process now.

Why does Asp.Net Core 2.1 WebApi return a 500.19 error?

I have a small webapi service, which works under Visual Studio but doesn't work under IIS.
I did the next:
New application was added to the default web-site in IIS console.
Application was published into app folder from VS via File System
(Framework-dependent and Portable options were selected).
When I try access folder with my app (like http://localhost/example/) I receive 500.19 error with code 0x8007000d. I read this error can happen if ApplicationHost.config or Web.config has wrong XML options. I use default Web.config file (ApplicationHost.config is not used by me) which VS generate, and I don't understand what can be bad in it. Here's my Web.config 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=".\Service.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
Lex Li wrote an excellent article: https://blog.lextudio.com/the-horrible-story-of-publishing-net-core-web-apps-for-beginners-6121662dd8c4, which described issues with publishing .NET Core Web Apps.
In my case, I hadn't installed the ASP.NET Core Hosting Bundle. A simple solution which is hard to be found because it is difficult to understand what should be searched for.
I ran into the exact same issue and in addition to the marked correct answer, this is what worked for me:
I installed the ASP.NET Core Hosting Bundle and was still receiving the same error.
Repairing the installation resolved my issue.
Programs and Features -> Repair "Windows Server Hosting"
"If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.
If the Hosting Bundle is installed after installing the 64-bit (x64) version of .NET Core, SDKs might appear to be missing (No .NET Core SDKs were detected). To resolve the problem, see Troubleshoot ASP.NET Core projects." - Install the .NET Core Hosting Bundle

.net core application error 502.5 if run as virtual directory in IIS

I am having problem configuring .net core application to work as virtual directory in iis.
If i start .net core application directly with its port it works fine.
I am getting 502.5 response and in event viewer there is this message
Application 'MACHINE/WEBROOT/APPHOST/DEFAULT WEB SITE' with physical root 'C:\inetpub\wwwroot\' failed to start process with commandline ' ', ErrorCode = '0x80070057 : 0.
I have removed parent handlers in .net web.config like this
<handlers>
<remove name="httpPlatformHandler"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
</handlers>
In order to run an ASP.NET Core application make sure you:
Have the ASP.NET Core Web Hosting Bundle (required for a server!)
Publish your application - should include a web.config
Deploy the Publish output to your server
Set up an Application Pool
Set .NET Framework to none (optional but usually a good idea)
Use an account that has read permissions in the virtual folder
The hosting bundle includes the ASP.NET Core Module for IIS which allows IIS to launch. Without ASP.NET Core apps will not run on IIS.
You also need to publish your application, which produces a final output folder that contains your binaries and config files including a web.config in the root and a wwwroot root folder with your content. To test you should make sure you can run your app from the command line with:
dotnet yourMainAssembly.dll -c Release
If this doesn't work fix this first as this is essentially what IIS fires. once the standalone works you can try using IIS.
ASP.NET Core projects created in Visual Studio automatically include a web.config and that should have everything you need to run under IIS. For a basic setup that should be all you need. The generated web.config should take care of getting your app running.
If you're using a virtual you might have an issue with the parent side configuration bleeding into your virtual because virtuals inherit settings from the parent. If that's the case either choose the same version of .NET Framework for your application pool, or share the application pool with the parent. Alternately you can use <clear /> in the <handlers> section to clear out any handlers from up the hierarchy.
<configuration>
<system.webServer>
<handlers>
<clear>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" startupTimeLimit="3600" requestTimeout="23:00:00">
<environmentVariables />
</aspNetCore>
</system.webServer>
</configuration>
I have a blog post with a lot more details on hosting on IIS along with some additional configuration for static files here:
Publishing and Running ASP.NET Core Apps under IIS
IIS Rewrite Rules and Static File Configuration for ASP.NET Core

ASP.NET Core page not found when publishing to IIS

I updated my ASP.NET Core project from RC1 to 1.0 RTM (with preview2 tooling), everything went fine. I can debug in Visual Studio without problems. Next I would like to upload the site on a Windows Server 2008 R2 and IIS 7.5. I installed the necessary Windows Hosting tools and created the web application in the IIS. The problem is, that after I tried to open the page, it returned a 404 error. As I see in the task manager, my application is running, but stops in listening mode.
In the log file I only see these entries:
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\MySite
Now listening on: http://localhost:20706
Application started. Press Ctrl+C to shut down.
It seems like there is some problem with the IIS integration. My web.config file looks 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="..\..\approot\MySite\MySite.exe" arguments="" forwardWindowsAuthToken="true" stdoutLogEnabled="true" />
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
I tried some workarounds from GitHub, which affected the Startup.cs file's Configure method without any success.
Any ideas?
FYI.. This web.config file was missing in the app folder.
This file should be at: C:\wwwwroot\myapp\
<?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=".\XXX.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
Don't forget to replace XXX.exe with the correct name of your Web API exe name.
Ok, I had multiple problems, but the two main reasons why my site didn't work:
I cannot start the code from two separate places. I originally put the wwwroot content under the wwwroot folder (not so suprising), and the rest to the approot. Now everything should be in the same folder.
My release versions didn't want to work. I must use the contents of the debug folder. I don't know why.
And now, everything is ok.
please click on .cshtml file in Views folder and set build action=Content in right bottom panel in Visual Studio. My problem has been solved

Categories