简体   繁体   中英

Get HTTP 500 error hosting ASP.Net Core MVC app in IIS

I am new to ASP.Net Core and trying to host my first simple MVC app in IIS. I have installed the IIS hosting bundle; published my MVC project to a folder using Visual Studio and then, created an IIS website with it's physical path set to the published folder. When I test it using url http://localhost:5008/home/CallApi, however, I am getting a 500 error that says "This page isn't working. localhost is currently unable to handle this request.". I can run the MVC app from within VS (selfhost, not through IIS, on a different port), it works fine there. What am I doing wrong here?

If you want to deploy ASP.Net Core MVC applications to IIS, you need to install the .NET Core host bundle, otherwise "500 Error" will appear. If you successfully install the .NET Core host bundle, you can find AspNetCoreModuleV2 in Modules:

在此处输入图片说明

Download the installer using the following link:

https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer

After adding the site, you need set the .NET CLR version to No Managed Code:

在此处输入图片说明

For more information about using IIS to host ASP.NET Core on Windows, you can refer to this link:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1

UPDATE:

I suggest you enable viewing of PII logs so that we can view more detailed information about the error:

public void ConfigureServices(IServiceCollection services)
{
    IdentityModelEventSource.ShowPII = true;
    ....

You can refer to this link, which contains similar questions:

"InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'"

For those with the same issue, I found that no setup guide I found mentions what was, for me, a required step:

  1. Open IIS Manager
  2. Navigate to [Server]\\Sites[Your site]. A folder is listed for your .NET application, but the icon shows as an ordinary folder, as if in Windows Explorer.
  3. Right-click the folder and select, "Convert to Application".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM