.NET 核心应用程序 |IIS |HTTP 错误 500 - 无法加载配置.异常消息:需要属性“processPath" [英] .NET Core App | IIS | HTTP Error 500 - Could not load configuration. Exception message: Attribute 'processPath' is required

查看:26
本文介绍了.NET 核心应用程序 |IIS |HTTP 错误 500 - 无法加载配置.异常消息:需要属性“processPath"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在同一站点的 Windows Server 2019 中的 IIS 中托管两个应用程序.其中一个应用程序是一个网站的前端,在 Angular 中,另一个是网站的 API,在 ASP.NET MVC (.NET Core 2.2.8) 中.
前端应用程序的 URL 是 site_url/portal,API 是 site_url/api.

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.

在使用 API 的其他操作之前,必须使用 Windows 身份验证从 site_url/api/identity URL 请求 JSON Web 令牌.前端似乎工作正常,但尝试在质量控制环境中访问 site_url/api/identity API 会产生HTTP 错误 500.0 - 内部服务器错误".
我在 IIS 中激活了详细日志,事件查看器中的错误消息是无法加载配置.异常消息:需要属性processPath"."
API 的 web.config 文件确实有一个进程路径:

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=".logsstdout" hostingModel="InProcess" forwardWindowsAuthToken="true"/>
    </system.webServer>
  </location>
</configuration>

此外,IIS 错误页面显示了一些我觉得很奇怪的内容.请求 URL 正确,但物理路径为 application_pathidentity.《身份》是一个MVC控制器,而不是一个文件.

Aditionally, the IIS error page shows something which I find strange. The request URL is correct, but the physical path is application_pathidentity. "Identity" is an MVC controller, not a file.

安装了 .NET Core 2.2 Windows Hosting Bundle 并设置了 .NET 路径环境变量.
应用程序池标识为应用程序用户,.NET CLR 版本设置为无托管代码".
该站点同时启用了匿名身份验证(用于前端登录页面)和 Windows 身份验证.

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.

问题是,我在开发环境和干净的 Azure 虚拟机中以完全相同的方式托管应用程序,并且它们在两者中都可以使用,这让我认为这与 IIS 或质量控制机器本身.

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?

推荐答案

一个缺失的配置导致了这个错误,直到我添加它:环境变量 ASPNETCORE_ENVIRONMENT

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=".logsstdout" hostingModel="InProcess" >
    <environmentVariables>
      <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
    </environmentVariables>
  </aspNetCore>
</system.webServer>

您可以将它放在 web.config 中,但如果您从 Visual Studio 发布新版本的 Web 应用程序,它将被删除.为避免这种情况,请将其放在 applicationHost.config 中(与您的站点对应的位置).

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).

这篇关于.NET 核心应用程序 |IIS |HTTP 错误 500 - 无法加载配置.异常消息:需要属性“processPath"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆