“500 - Internal server error” when calling ASP .Net Core 2.1 Web API on Windows Server

守給你的承諾、 提交于 2021-02-19 04:32:38

问题


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? Thanks...


回答1:


I finally figured it out! 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. Thanks everyone for your time and support. I really appreciate it!




回答2:


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://docs.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.

Hope you'll find this useful.



来源:https://stackoverflow.com/questions/52270350/500-internal-server-error-when-calling-asp-net-core-2-1-web-api-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!