.net Core API not working on IIS - api

I'm new to this .NET Core stuff and this is the first time I've tried to deploy one of these.
The project is an API for an Angular front end I'm building and takes HTTP requests and returns JSON. When I run it in Visual Studio on my box it is all fine. I'm running VS2017 and have .NET Core 2.0.0 installed.
I publish to a folder on the web server and it all seems to work fine, but when I try to access the API I get a 404 not found error. The server is running .NET 2.0.6 (I tried to get 2.0.0 but couldn't find it in the Hosting Bundle Installer.
If I delete the web.config the HTML file will then show up, but obviously the API doesn't work. But as the HTML file shows up there is no issue with permissions and access. There's nothing in the Event Viewer. I've also tried turning on the logging in the web.config, but it doesn't log... probably not getting far enough to.
Web config 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="dotnet" arguments=".\RawMaterialsSystem.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: f01b1621-2ced-4ad2-9ae6-004e03b0e043-->`

STEP 1: Change your web.config file to this
<?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="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
STEP 2:
In visual studio, right click the .net core app project and select "Publish"
Then publish it as a folder under bin\Release\netcoreapp2.0\publish
STEP 3:
In IIS --> Sites --> Right click on YourSite --> Under "Manage Website" select "Advanced Settings"
Make sure the "Physical Path" you are pointing to is the "publish" folder as the app directory, and not the "netcoreapp2.0" folder

Related

web.config is replaced with default in DevOps drop

ASP.NET Core 3.1 project uses the following line in csproj to copy a customized web.config from the wwwroot folder into the output folder:
<ItemGroup>
<Content Update="wwwroot\Web.config" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Link="%(Filename)%(Extension)" />
</ItemGroup>
The project is compiled using Azure DevOps classic (non-YAML) pipeline:
.NET Core task (Task version 2.0), command restore
.NET Core task (Task version 2.0), command build
.NET Core task (Task version 2.0), command publish with [x] Publish web projects, [x] Zip published projects and [x] Add project's folder name to publish path
Publish build artifacts task (Task version 1.0)
Builds up to July 2020 retained the customized web.config in the build artifact as expected, just with the following lines being injected to the customized web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<...>our custom settings defaultDocument, staticContent, rewrite and rewriteMaps</...>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Something.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>
<!--ProjectGuid: SOME-GUID -->
But the builds made yesterday and today contains different web.config, missing the customized parts while adding a <location> tag:
<?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=".\Something.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: SOME-GUID -->
Note: There were no builds between July and yesterday. The only change made in the project source was just a few unrelated minor text changes in Razor views. The pipeline definition is kept unchanged for at least a year.
July's build agent logged these versions:
Current agent version: '2.171.1'
Current image version: '20200630.0'
Downloading task: DotNetCoreCLI (2.171.3)
Downloading task: PublishBuildArtifacts (1.158.3)
November's build agent logged these versions:
Current agent version: '2.177.1'
Included Software: https://github.com/actions/virtual-environments/blob/win19/20201116.1/images/win/Windows2019-Readme.md
Current image version: '20201116.1'
Downloading task: DotNetCoreCLI (2.175.0)
Downloading task: PublishBuildArtifacts (1.158.3)
Why the web.config in the artifacts no longer contains the customized part? How to fix it?

After upgrading to ASP.NET Core 3.0, I get "Could not create stdoutLogFile ErrorCode = -2147024893."

I'm upgrading an existing ASP.NET Core 2.2 application to 3.0.
When I publish and host my APIs inside local IIS, I get the HTTP Error 502.5 - Process Failure page. The point is, I don't see the logs being written to the stdoutLogFile location.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\bin\MyApplication.dll" stdoutLogEnabled="true" stdoutLogFile=".\bin\Logs\" hostingModel="inprocess" />
</system.webServer>
</configuration>
I've changed the output folder from \bin\Debug\netcoreapp3.0\ to \bin\ via these configurations:
<PropertyGroup>
<OutputPath>.\bin</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
I also have a folder called Logs in my \bin\ folder.
But when I call my API, I get this error in Error Viewer:
Warning: Could not create stdoutLogFile
C:\PathToMyProjectFile\bin\Debug\netcoreapp2.2_19212_2019102292022.log,
ErrorCode = -2147024893.
The point is, I'm not using 2.2 anymore. How should I solve this?
you have to modify the generated web.config by removing the "V2" in modules="AspNetCoreModuleV2", in order to have: modules="AspNetCoreModule".
Hope this helps

Cannot start website because of <handlers> in web.config

I have taken over the development of a software product that we currently deploy on an IIS server. Initially it was running with ASP.net core 2.0 but since I would like to use EF, I have configured the software to use 2.1.
The problem is, when I deploy a new version of our software, I cannot run it successfully. I tried to track down the error and i recognized that the web.config of the successfully running version and the new published version differ from each other.
Here's the version that runs just fine:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" arguments=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
And this does not work:
<?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=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
Obviously, it's just the handler that makes the difference. When I manually remove it, the software runs fine. How can i make sure that in future publishing processes via VB 2019, this handler is not added to the web.config? Is there any setting that I can make to prevent this error?
For ignoring the web.config during publishing, you could try <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled> in *.csproj like
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
For more information, you could refer web.config file
Unfortunately I cannot reconstruct that initial error message but I solved the problem in the meantime.
The problem was a <handler> tag that was added to the web.config during the publishing. We use a nested website structure with one main website and 4 sub-sites. In this configuration, the handler in the web.config must be removed according to documentation from Microsoft. My former colleague wrote a small xdt-transform script a while ago that was supposed to remove the tag when publishing the software. It always worked fine but it stopped working when I updated the SDK to 2.1. So the handler-tag was added to the web.config and that's why I could not access the website in the first place.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document->Transform">
<system.webServer>
<handlers xdt:Transform="Remove" />
</system.webServer>
</configuration>
I figured out that the generated web.config had an additional <language>-tag before the <system.webServer>-tag. Adding the language-tag to the remove script made the script work again. Now that problem was solved and I could at least connect to the website.
But after connecting I received a HTTP Error 502.5. This was due to an old 2.0.7 version of the runtime that was installed on the server. After updating to 2.2 the website finally was rendered correctly.

ASP.NET Core 1.1 - Setting the environment

I use ASP.NET Core 1.1.
When I publish my application the IHostingEnvironment always return the environment as "Production".
I made some attempts via the web.config as follows:
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
Unfortunately it doesn't has any effect.
I also get a warning about that the aspNetCore is invalid child of system.webServer...
I have seen at the project.json the scripts entry that runs dotnet publish-iis command but couldn't find any environment parameter.
I have tried to pass the publish command --iis-command (As described in this post) but it doesn't identify this parameter.
I will highly appreciate your thoughts about it...

Deploying asp.net core rc2 web app on IIS8 / Windows Server 2012

I've managed to publish my app and deploy it to my server, but I can't seem to make it run via IIS. I'm getting error 0x8007007b Cannot read configuration file.
My web.config, after publishing, looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\RetailGuardian.Web.exe" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
Edit: In case the problem is down to the app or how I've published it:
The app targets net452
There's a postpublish script: dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%
I publish the app using dotnet publish ./src/RetailGuardian.Web/ --framework net452 --runtime win7-x64 -c Release
This creates a series of outputs at ./src/RetailGuardian.Web/bin
To deploy, I'm coping ./src/RetailGuardian.Web/bin/Release/net452/win7-x64/publish onto my server and setting this as the physical path in IIS. Setting the .NET CLR version for the app pool to 'No managed code'
Unfortunately I can't even get any log output as logging fails due to being unable to read the configuration file :(