简体   繁体   English

无法在本地以及带有 IIS 的服务器上运行我的 .net 核心应用程序

[英]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.我创建了一个 .net core api(版本 2.2.0),当我尝试在 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.我验证了我的 web 配置,它似乎有正确的值集。启用日志记录和日志文件为空。

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.还尝试将 IIS_IUSRS 权限授予输出文件夹。 It didn't make any difference.它没有任何区别。 Having said that error code "'0x80004005' " suggests a permission error.话虽如此,错误代码“'0x80004005'”表示权限错误。 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.确保您在 iis 中正确发布站点。 Your site root folder has enough permission to access it by iis.您的站点根文件夹有足够的权限可以通过 iis 访问它。 assign the iis_iusrs and iusr permission to the site folder.将 iis_iusrs 和 iusr 权限分配给站点文件夹。 your application pool identity is set application pool identity or local system.您的应用程序池标识设置为应用程序池标识或本地系统。 anonymous authentication is enabled.启用匿名身份验证。 and you installed the iis asp.net feature.并且您安装了 iis asp.net 功能。 make sure your site binding is correct and the application pool is using correct .net version and running under integrated application pool.确保您的站点绑定正确,应用程序池使用正确的 .net 版本并在集成应用程序池下运行。

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.当 IIS 无法执行 dotnet 进程时,ASP.NET Core 中会出现 HTTP 错误 502.5 - 错误网关和 HTTP 错误 502.5 - 进程失败错误消息。

  • .NET Core Runtime is not installed未安装 .NET Core 运行时
  • web.config file has not been transformed web.config 文件尚未转换

To resolve this issue you could refer one the below-suggested way:要解决此问题,您可以参考以下建议的方法:

  1. Install the .NET Core Runtime安装 .NET Core 运行时

The most common reason for this to occur is when you haven't installed the .NET Core runtime on the server.发生这种情况的最常见原因是您尚未在服务器上安装 .NET Core 运行时。

You can download the latest .NET Core runtime from Microsoft's .NET download page .您可以从 Microsoft 的.NET 下载页面下载最新的 .NET Core 运行时。

After installing Bundle stop iis and start again.安装 Bundle 后停止 iis 并重新启动。

Publish a Self-Contained Deployment发布独立部署

If you don't want to install the .NET Core Runtime.如果您不想安装 .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. .NET Core Web 应用程序的替代方法是在自包含部署模式下发布它们,其中包括应用程序旁边所需的 .NET 运行时文件。

在此处输入图片说明

If you go with this option, you'll also need to choose a target runtime: win-x86, win-x64, osx-x64, or linux-x64.如果您选择此选项,您还需要选择一个目标运行时:win-x86、win-x64、osx-x64 或 linux-x64。 Because self-contained deployments are not portable.因为独立部署不可移植。

  1. Transform your web.config file转换您的 web.config 文件

Another reason for this error to occur is when you deploy an untransformed web.config file.发生此错误的另一个原因是部署未转换的 web.config 文件时。

This is likely to be your issue if you had a previously working web application and merely deployed a new version of it.如果您有一个以前可以运行的 Web 应用程序并且只是部署了它的新版本,这很可能是您的问题。

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.在 ASP.NET Core 应用程序中,web.config 文件包含将请求定向到 AspNetCoreModule 的处理程序和定义和配置 ASP.NET Core 进程以执行 Web 应用程序的 aspNetCore 元素。

Here is a minimal web.config file for an ASP.NET Core application:这是 ASP.NET Core 应用程序的最小 web.config 文件:

<?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.问题是未转换的 web.config 包含变量 %LAUNCHER_PATH% 和 %LAUNCHER_ARGS% 而不是正确的路径。 When IIS tries to run ASP.NET Core, it uses %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct path and arguments.当 IIS 尝试运行 ASP.NET Core 时,它​​使用 %LAUNCHER_PATH% 和 %LAUNCHER_ARGS% 而不是正确的路径和参数。 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.要修复 ASP.NET Core 中的 HTTP 错误 502.5,您需要转换 web.config 并替换 IIS Web 服务器上未转换的 web.config 文件。

steps to transform web.config file:转换 web.config 文件的步骤:

This transformation takes place when you choose to publish your web application.当您选择发布 Web 应用程序时,就会发生这种转换。 The transformed web.config ends up in the published output folder.转换后的 web.config 最终位于已发布的输出文件夹中。 Therefore, you simply need to publish your web application and copy the resulting web.config file onto the server.因此,您只需发布您的 Web 应用程序并将生成的 web.config 文件复制到服务器上。

In a transformed web.config file, the aspNetCore element will look something like this:在转换后的 web.config 文件中,aspNetCore 元素将如下所示:

<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. %LAUNCHER_PATH% 已替换为 dotnet,%LAUNCHER_ARGS% 已替换为主 Web 应用程序 dll .\\MyApplication.dll 的路径。

links:链接:

Publish an ASP.NET Core app to IIS 将 ASP.NET Core 应用发布到 IIS

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 ASP.NET Core API 部署到本地 IIS 错误 500 - Deploy ASP.NET Core API to Local IIS Error 500 使用Volley向具有API(.net核心)的本地Microsft服务器发布请求android应用 - POST request android app using volley to local Microsft server with API (.net core) IIS ASP.NET Core 应用程序在部署后无法启动 - IIS ASP.NET Core app failed to start after deploying .net Core API在IIS上不起作用 - .net Core API not working on IIS NativeScript:我无法连接到我的本地 .NET 核心 API - NativeScript: I can't connect to my local .NET Core API Antimalware Service Executable 使用高 CPU 并阻止运行 IIS.Net Core App - Antimalware Service Executable uses High CPU and blocks running IIS .Net Core App 当我添加对我的项目的引用时,在 iis 上发布 .net 核心 api 失败 - publish .net core api on iis failed when i add reference to my project 在同一 Z5DA5ACF461068EFB27EZEC76 服务器上部署 .net MVC 和 api 时,我是否应该为我的 API 使用 localhost - Should I use localhost for my API when deploying .net MVC and api on the same IIS server ASP.NET Core Web API Entity Framework Invalid object name only when running through IIS Server - ASP.NET Core Web API Entity Framework Invalid object name only when running through IIS Server .net 核心 api 在本地 docker 容器中不起作用,但在我的视觉工作室中起作用 - .net core api doesn't work in a local docker container, but works in my visual studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM