Reputation: 251
I'm trying to host a .net Core API in IIS. When I have it running in Visual Studio everything is working correctly. For deployment I first published the project to a folder, copied the contents to the desired location and created an application in IIS. It is set to use an application Pool thats cofigured with "No managed code".
When I try calling one of the available Endpoints (through the frontend or manually) I receive an http 500 Error (Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.)
I can't find any meaningful logs on the Server. Only in the Event Viewer could I find an Error event.
"Could not load configuration. Exception message: Attribute 'processPath' is required."
Now im not sure why this would be the case because the processPath attribute in the Web.config of the project is definitely present and is generated like this when publishing. It looks like:
<?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=".\MyApplication.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
The core Hosting Bundle is installed. A complete restart isn't really viable on this server (or at least I want to avoid it). For that reason I ran
net stop was /y
net start w3svc
to pick up on any changes made.
I'll be happy about any ideas and advice on how to resolve this. Thanks a lot in advance!
Upvotes: 9
Views: 13368
Reputation: 101
Make sure to "Convert to Application" if hosting in subfolder in IIS! This was my issue. I didn't have to modify anything else.
Upvotes: 10
Reputation: 434
This error occured to me because I had accidentally setup azure virtual path mapping as "directory" when it should have been "application"
Upvotes: 3
Reputation: 164
Another missing configuration caused this error for me until I added it: environment variable ASPNETCORE_ENVIRONMENT
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApplication.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
You can put this in web.config, but it will get removed if you publish a new version of the web app from Visual Studio. To avoid that, put it in applicationHost.config instead (in the location corresponding to your site).
Upvotes: 0
Reputation: 251
So it took me longer than I like to admit to find the cause of this issue. But for anyone who might stumble over this in the future heres what helped me.
I hosted the project in two subfolders under the desired Site in IIS. So Desired_Site -> Subfolder1 -> Subfolder2 -> actual project files. My guess is that IIS couldn't handle the web.config file being in this location. When I moved
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApplication.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
from the projects web.config file to a web.config in Subolder1 (adjust paths accordingly) everything is working as expected. Should you run into the same problem make sure the folder structure you are trying to host under is as flat as possible.
Upvotes: 7