"500 - Internal server error" when calling ASP.NET Core 2.1 Web API on Windows Server - asp.net-core

I have an ASP .Net Core 2.1 Web API which I've deployed to a new server we recently purchased (running Windows Server 2016 Standard). The API works perfectly on both my development PC and our old server (running Windows Server 2012 R2). But on this new server, I get this error:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
I remember a year ago also struggling a lot trying to get it to run on our old server. I did eventually get it to work, but I can't remember what I did! Is there any way to get more information on this error? I've checked the Windows Event Viewer on the new server and there is nothing there. Also, although I've got stdoutLogEnabled="true" in my web.config, it's not generating the log - and I've created the \logs\stdout path so the folders do exist...
I've also got app.UseDeveloperExceptionPage(); in my Startup.cs, but I'm not getting any more info that a simple 500 internal server error.
This is what my web.config looks like:
<?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=".\PropWorx.API.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: cfa62a1f-c5f6-43f8-bcbe-04068e40b803-->
I've also got the Microsoft .NET Core 2.1.1 - Windows Server Hosting installed and the Microsoft .NET Core Runtime - 2.1.1 installed (both x86 and x64).
Like I said it works on my development PC and on our old server, so it must be a configuration issue on the new server. Is there a way I can get more detailed error information other than just 500 Internal Server Error?

I had an outdated version of the .NET Core Windows Server Hosting bundle. I had version 2.1.1 installed. I removed it, and installed version 2.1.4 and now it works.

Various reasons can cause this issue.
if this is happening only in the browser (working with curl or postman), it can be a pre-flight request error, then you will need to modify UrlScan.ini (I assume this didn't changed on Windows 2016) at the following path (C:\Windows\System32\inetsrv\urlscan), add OPTIONS to [AllowVerbs].
if not, make sure you followed the steps provided in Microsoft documentation:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x
You may need to install Visual C++ 2015 Redistributable on the server
To get logs, change "IncludeScopes": true, in your appsettings.json logging section, check also the event viewer.

Related

Login issue after publishing .Net Core 3.1 web app to IIS

I created a .Net Core 3.1 MVC application that is using induvial user accounts as authentication. I deployed the site to IIS, which works. However when I tried to log in with an account I know that works, the login does not succeed, and I am directed back the default route of the application. No error messages or log entries that I can find. The application pool is set up for non managed code, and is running under an account that has dbo rights to the database. Any thoughts as to what the issue might be?
http://localhost:44360/ running on server on Visual Studio 2022
http://localhost:2710/ running on server on IIS
http:// domain . com not working
It is difficult for everyone to help you without error messages. Have you tried swapping to a development environment to see the details of the error?
Locate the Web.config file and adjust it to set the ASPNETCORE_ENVIRONMENT environment variable as follows:
<aspNetCore processPath="dotnet" arguments=".\ProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
This method worked for me to find the error, you can try it.
This field already exists in the web.config file.
It gives a warning when the user is wrong, but when we enter the correct user information, it does not create cookies or sessions and does not fall into any errors.

HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure Application Xbap

Recently I have had this problem that comes up often but I don't understand the reason for it.
With IIS I have my web site with my api and when I call them I get an answer but I added an application to my web site and this one sends me this error.
My api are in: C:\inetpub\wwroot\V4_1\
And the Xbap application can be found in: C:\Content\AppliWindows\Xbap\
Some of the servers I use with the same files don't have this problem.
Web.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Spec.Locbus.V4.Services.FrontEnd.exe" arguments="" requestTimeout="00:20:00" stdoutLogEnabled="false" forwardWindowsAuthToken="false" stdoutLogFile=".\logs\stdout">
<environmentVariables />
</aspNetCore>
</system.webServer>
</configuration>
<!--ProjectGuid: 821a3cf1-7c3b-4e36-8868-69fd8b417331-->
In Windows event log I get this error but it doesn't give me any more information:
Application '/LM/W3SVC/2/ROOT/content' with physical root
'C:\content' failed to start process with commandline
'.\Spec.Locbus.V4.Services.FrontEnd.exe ' with multiple retries.
Failed to bind to port '7993'. First 30KB characters of captured
stdout and stderr logs from multiple retries:
I know I get the same error when I try to call my api and I didn't install net.core2.2.8 but I installed it correctly and my api works.
The server I'm on is running Windows2019.
Asp.NET diagnostics seems to be good except for 2.2.8 at end of life :
System Time: 17/11/2020 15:57:29
Processor Architecture: AMD64
OS: Microsoft Windows NT 10.0.17763.0
Server Type: IIS
Scan 32 installed module(s).
ASP.NET Core module version 2 is installed for .NET Core 2.2 and above: C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll (13.1.20295.10).
Scan 45 registered handler(s).
Found a valid ASP.NET Core handler as { Name: aspNetCore, Path: *, State: Enabled, Module: AspNetCoreModuleV2, Entry Type: Local }.
Visual C++ runtime is detected (expected: 14.0, detected: 14.28.29325.2 built by: vcwrkspc): C:\Windows\system32\msvcp140.dll.
The application pool 'LocbusV4' is used.
Pool identity is IIS AppPool\LocbusV4
Please ensure pool identity has read access to the content folder C:\inetpub\wwwroot\V4_1.
Pool bitness is 64 bit
Scan aspNetCore section.
"processPath": .\Spec.Locbus.V4.Services.FrontEnd.exe.
"arguments": .
"hostingModel": .
"runtimeTarget": .NETCoreApp,Version=v2.2/win-x64.
Runtime is Microsoft.AspNetCore.All/2.2.8.
.NET Core version 2.2.8 is end-of-life. Please upgrade to a supported version.
Runtime 2.2.8 requires ASP.NET Core module version 12.2.19109.5. Installed version 13.1.20295.10 might not be compatible.
Please refer to pages such as https://dotnet.microsoft.com/download/dotnet-core/3.1 to verify that ASP.NET Core version 13.1.20295.10 matches the runtime of the web app.
Has anyone ever had this problem and has a solution?
Thank you in advance.
I finally succeeded in creating a second site by creating the sub-application in this one and with URL rewriting redirecting the calls intended for the application from site 1 to the site of the app.

Unable to run my .net core app in local as well as on server with IIS

I created a .net core api (version 2.2.0) and I'm getting the following error when I try to run on IIS.
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
I verified my web config and it appears to have correct set of values.Enabled logging and log file comes as empty.
Event log shows the following error.
I installed hosting bundle and checked still getting same error. Also tried giving permission to IIS_IUSRS to the output folder. It didn't make any difference. Having said that error code "'0x80004005' " suggests a permission error. Still couldn't figure it out. Appreciate any help !
Web config
<?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=".\MyApi.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>`enter code here`
<!--ProjectGuid: 4d7644bb-9348-46f9-8397-95f01e03d599-->
Make sure you publish the site properly in iis. Your site root folder has enough permission to access it by iis. assign the iis_iusrs and iusr permission to the site folder. your application pool identity is set application pool identity or local system. anonymous authentication is enabled. and you installed the iis asp.net feature. make sure your site binding is correct and the application pool is using correct .net version and running under integrated application pool.
The reason behind the error message
The HTTP Error 502.5 - Bad Gateway and HTTP Error 502.5 - Process
Failure error messages occur in ASP.NET Core when IIS fails to execute
the dotnet process.
.NET Core Runtime is not installed
web.config file has not been transformed
To resolve this issue you could refer one the below-suggested way:
Install the .NET Core Runtime
The most common reason for this to occur is when you haven't installed the .NET Core runtime on the server.
You can download the latest .NET Core runtime from Microsoft's .NET download page.
After installing Bundle stop iis and start again.
Publish a Self-Contained Deployment
If you don't want to install the .NET Core Runtime. An alternative for .NET Core web applications is to publish them in the Self-Contained deployment mode, which includes the required .NET Runtime files alongside your application.
If you go with this option, you'll also need to choose a target runtime: win-x86, win-x64, osx-x64, or linux-x64. Because self-contained deployments are not portable.
Transform your web.config file
Another reason for this error to occur is when you deploy an untransformed web.config file.
This is likely to be your issue if you had a previously working web application and merely deployed a new version of it.
In ASP.NET Core applications, the web.config file contains a handler that directs requests to the AspNetCoreModule and an aspNetCore element that defines and configures the ASP.NET Core process to execute your web application.
Here is a minimal web.config file for an ASP.NET Core application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
The issue is The untransformed web.config contains the variables %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct paths. When IIS tries to run ASP.NET Core, it uses %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct path and arguments.
To fix the HTTP Error 502.5 in ASP.NET Core, you need to transform the web.config and replace the untransformed web.config file on the IIS web server.
steps to transform web.config file:
This transformation takes place when you choose to publish your web application. The transformed web.config ends up in the published output folder. Therefore, you simply need to publish your web application and copy the resulting web.config file onto the server.
In a transformed web.config file, the aspNetCore element will look something like this:
<aspNetCore processPath="dotnet" arguments=".\MyApplication.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
%LAUNCHER_PATH% has been replaced by dotnet and %LAUNCHER_ARGS% has been replaced by the path to the main web application dll .\MyApplication.dll.
links:
Publish an ASP.NET Core app to IIS

ASP.NET Core 1.0 Web.Config Issue

My first stab at trying to implement an ASP.NET Core Application to Hosted IIS Server.
I believe I could a malformed XML aspNetCore Attribute of the web.config
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
%LAUNCHER_PATH% is a placeholder.
based on this information
I changed the processPath="dotnet" and arguments=".\WebDevX1.dll" however running with that produces 502.5 Error. Running with just placeholders works fine. It was my understanding that I need to change those placeholders in order to publish to the Hosted Server.
Whether I modify the placeholders in those 2 attributes or not, the web.config aspNetCore Attribute still shows an error
When I run locally from Visual Studio, the web.config reverts back to the placeholders:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
ASP.NET Core 1.0.0 is installed locally
And my Host indicates they support .NET Core defaultly.
If someone has any insight as to what I'm missing I would really appreciate it.
You should have the publish-iis tool configured to run as a post-publish script. This tool replaces LAUNCHER_PATH and LAUNCHER_ARGS. You can find more details about this in my post about running ASP.Net Core applications with IIS.
After project.json to .csproj transition the publish-iis tool was converted to an MSBuild task (the TransformWebConfig task)

HTTP Error 404.3 - Not Found" while browsing wcf service on Windows Server 2008(64bit)

I am developing an application based on .Net Framework 3.5 sp1 and hosted on windows server 2008(64bit).
While browsing wcf service (.svc) locally every things is ok but while browsing with full domain URL, it got an error.
local address is like this: http://localhost/MyService.svc
and domain address is like this: http://MySite.ir/MyService.svc
by the way pages (.aspx) and other files work correctly both on localhost and with domain address.
any Idea would be appreciated
Here is detailed error:
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
Detailed Error Information
Module: StaticFileModule
Notification: ExecuteRequestHandler
Handler: StaticFile
Error Code: 0x80070032
Requested URL: http://MySite.ir:80/MyService.svc
Physical Path: D:\inetpub\vhosts\MySite.ir\httpdocs\MyService.svc
Logon Method: Anonymous
Logon User Anonymous
Please make sure you've activated WCF components from here.
Or alternate and easy way is, go to control panel -> Turn Windows feature on or off -> and make sure you've all the options ticked as mentioned in below screenshot.
You might need to activate each box and accept in case you get errors when activating all features at once
OK, here is the answer:
Go to Handler Mappings | Add Handler Manager --> And then add below information
Request Path: *.svc
Type: System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Name: svc-Integrated
If anyone has this issue on Windows Server 2012, Bill Moon's answer here solved it for me:
"For Windows Server 2012... From the Server Manager, click on Add roles and features, select the appropriate server, then select Features. Under .NET Framework 4.5 Features, you'll see WCF Services, and under that, you'll find HTTP Activation."
I have windows 10 in my laptop and using visual studio 2015 for WCF development. WCF is running fine in visual studio but when hosted in IIS I got the same error.
I checked IIS handler. svc extension was missing. So I tried to add new handler in IIS as suggested by Mori in first answer. I didn't find type "System.ServiceModel.Activation.HttpHandler".
So I opened "Turn windows features On or Off" and installed features as highlighted in screen shot.
This worked for me.
If you're using .Net 4.x, the PublicKeyToken is 31bf3856ad364e35.
However, following this post about installing WCF Services properly in IIS, the handler was set up for me.
I wanted to add this as a comment to the answer but didn't have enough rep for it. I tried running ServiceModelReg and aspnet_regiis.exe with various flags and added HTTP Activation feature but it still didn't work. Even using the Handler mapping UI in IIS didn't work since it could not find System.ServiceModel.Activation.HttpHandler. What finally worked was adding the handler Mori mentions manually to my web.config file.
<system.webServer>
<handlers>
<add name="svc-Integrated" path="*.svc" verb="GET,HEAD,POST,DEBUG" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />
My project was running .Net 3.5 and IIS 7.5 on Windows 7 and IIS 7.0 on Win Server 2008 R2.
Try unchecking WCF HTTP activations from "Turn Windows featured on or off" window (See here) and re-install by going to
%windir%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\
and execute ServiceModelReg -i