.NET Core WebAPI IIS Deploying - iis

I have created a webAPI using .Net Core and trying to publish it to IIS. But getting HTTP 500.19.
It's looking for web.config file but I don't have it.
What should I do?

Did you installed this: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?tabs=aspnetcore2x&view=aspnetcore-3.1
If Yes check your permissions on the folder. The identity under which your web application runs in IIS may has not full access to the folder in which the web.config file is found. You could change your identity under the appPool or grant access to your folder. If you deployed into the wwwroot folder the IUser should have access to the folder.

When you publish your .net core in IIS please remember to install .net core web hosting bundle because it is not supported by default. IIS handle request based on different handlers. Even when you install the extension, aspnet core module is not registered. So please remember to set
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<aspNetCore processPath=".\myapp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
If the solution doesn't fix this. Then something in your web.config is corrupting the application. Please post a screenshot the detailed error message. Then we would know how to fix this completely.

Related

How to enable URL Rewrite in IIS with a .NET Core website

I have created / maintained .net mvc websites for many years and I am working on my first .net core website. I am using Windows server 2019 with IIS. My goal is to duplicate the rewrite rules I have created for my mvc websites on my new core website (one example is the canonical host name rule). I don't have any problems doing this in IIS for the new core website. My problem is when I publish changes, the web.config file on the server gets overwritten and the rules are removed (because I created them in IIS not in Visual Studio). .net core does not have a web.config file in Visual Studio to modify, but a default version is sent to the server when publishing.
Here is the default version if this helps:
<?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=".\websitename.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 81d237a0-1b33-43a4-8e2b-eed282153721-->
I resolved this issue by adding the below lines to the project file, which turns off creating/transforming the web.config file when publishing:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
My question is if my approach is an appropriate way to implement url rewrites? I am using IIS, so a web.config file is required, but it isn't something I can edit in Visual Studio for core like I could for mvc (at least I am not aware of how to do it).

.NET Core App | IIS | HTTP Error 500 - Could not load configuration. Exception message: Attribute 'processPath' is required

I'm trying to host two applications in IIS in Windows Server 2019, in the same site. One of the applications is a website's front-end, in Angular, and the other one is the website's API, in ASP.NET MVC (.NET Core 2.2.8).
The front-end application's URL is site_url/portal and the API's is site_url/api.
Before using the API's other actions, one has to request a JSON web token from the site_url/api/identity URL, using Windows Authentication.
The front-end seems to be working fine, but trying to reach the site_url/api/identity API in the quality control environment yields "HTTP Error 500.0 - Internal Server Error".
I activated detailed logs in IIS and the error message in Event Viewer was "Could not load configuration. Exception message: Attribute 'processPath' is required."
The API's web.config file does have a process path:
<?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=".\PortalAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" forwardWindowsAuthToken="true"/>
</system.webServer>
</location>
</configuration>
Aditionally, the IIS error page shows something which I find strange. The request URL is correct, but the physical path is application_path\identity. "Identity" is an MVC controller, not a file.
The .NET Core 2.2 Windows Hosting Bundle is installed and the .NET path environment variable is set.
The application pool identity is an applicational user, and .NET CLR version is set to "No Managed Code".
The site has both Anonymous Authentication (for the front-end login page) and Windows Authentication enabled.
The thing is, I have hosted the applications in the exact same way in both the development environment and a clean Azure virtual machine, and they work in both, which makes me think this has to do with some setting in either IIS or the quality control machine itself.
Does anyone have any idea what the problem and/or possible solutions might be?
A 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="dotnet" arguments=".\PortalAPI.dll" 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).

web.config in asp.net MVC core Project

I am really new to Asp.net MVC core , my visual studio is on macOS , so I had to publish my project on Azure. I wanted to transfer this project on Godaddy host. I download the files and uploaded on the Godaddy host. the problem is that it has Error 500. Is there any thing which I can do to fix it?
here is my webconfig ,
<?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=".\WebAppEver.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: F0AEADEA-9B69-4295-85F3-A3BDD9433AD4-->
Your host will need to setup their servers to support asp.net core. They must install the IIS module that supports asp.net core and allow the extra process to run that’s the asp.net core application.
You will also need to know what version of asp.net core is installed, or you should deploy a self hosted version.
For our shared hosting plans we do not offer asp .NET core 1 or 2. Best case is to get a server per the requirements to support asp .NET core 2.0. This requires any VPS or Dedicated environments running Plesk Onyx 17.8 for automated installer support.
Also, in order to see the detailed error message, add this to your web.config:
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed"/>
</system.webServer>
</configuration>

HTTP Error 502.5 running ASP.NET Core 2.0 app from IIS

I'm getting an HTTP 502.5 error when trying to run my ASP.NET core 2.0 web app from IIS.
I've installed the .NET Core Windows Server Hosting Bundle and checked all my IIS settings as per this document https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?tabs=aspnetcore2x
The 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=".\OscarWeb.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
The Windows event log produces the following errors.
It is IIS v6.2 running on Windows Server 2012 R2. The web application was built using ASP.NET Core 2.0.
When I run dotnet from the commandline as follows there are no errors:
dotnet oscarweb.dll
The first thing you have to do in this scenario is to create the logs folder if it is missing and check the stdout logs generated.
It can be several different things but from personal experience the most common issue i had was IIS not having enough permissions to run it. In IIS you can configure the Identity used in Advanced Settings. If it is using ApplicationPoolIdentity then change it to LocalSystem and see if it works. The logs in the stdtout file however will give you the answer.
The solution to this problem (in my case at least) was to reboot the web server. After installing the .NET Core Windows Server Hosting Bundle you need to reboot the server for them to be registered correctly.
Thanks to Chris Pratt (first comment underneath my question) for suggesting the answer :)
Not sure if your webconfig is complete. I believe aspnetcore tag needs to have the ASPNETCORE_ENVIRONMENT environment variable set as well.
<?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=".\OscarWeb.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="YourRuntimeEnv" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>

Unable to open ASP.NET Core website's Module in IIS

I've deployed ASP.NET Core 1.1.1 app in IIS-10 on Windows 10 following this tutorial. But when I try to open Modules in IIS, I get the following error [For clear view you can click on the image to zoom in]:
Note:
It's a development machine and already has installed as shown below:
The app pool for the app is as follows:
And the Web.config file:
<?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" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
UPDATE: Issue may have been related to this post
It turns out that ASP.NET Core Module is installed separately from the SDK and I needed to install ASP.NET Core Module for the above issue to be resolved as explained in this post. Thanks to #natemcmaster for helping me resolve the issue.

Resources