简体   繁体   English

HTTP 错误 404:在 IIS 上部署 Web API(最小 API NET 7)

[英]HTTP Error 404: Deployment of a Web API (minimal API NET 7) on IIS

I probably have a setup problem on IIS (it's a web server with real URL domain, so accessible from external at any time).我可能在 IIS 上遇到了设置问题(它是一个具有真实 URL 域的 Web 服务器,因此可以随时从外部访问)。 I have created a Web API with minimal API NET 7. Before testing out authetification, I tried to reach an endpoint first.我创建了一个具有最小 API NET 7 的 Web API。在测试身份验证之前,我尝试先到达一个端点。 I named this endpoint /api/test and defined it as [AllowAnonymous] .我将此端点命名为/api/test并将其定义为[AllowAnonymous] On the development server via Swagger everything is already running (also the login or generation of tokens).在通过 Swagger 的开发服务器上,一切都已经在运行(包括登录或令牌生成)。 But in the release web api version I commented out Swagger.但是在发布的 web api 版本中,我注释掉了 Swagger。

Now when I install the web app on IIS server, then when I call the app via IIS server (but also when I enter the address in browser itself) I get the message: HTTP Error 404.0 - Not Found Detailed error information is:现在,当我在 IIS 服务器上安装 Web 应用程序时,然后当我通过 IIS 服务器调用应用程序时(以及当我在浏览器本身中输入地址时),我收到消息: HTTP 错误 404.0 - 未找到详细的错误信息是:

  • Module: IIS Web Core模块:IIS Web 核心
  • Notification: MapRequestHandler通知:MapRequestHandler
  • Handler: StaticFile处理程序:静态文件
  • Error code: 0x80070002错误代码:0x80070002
  • Requested URL: http://api.testapp.com:64591/api/test请求的网址: http ://api.testapp.com:64591/api/test
  • Physical path: C:\inetpub\wwroot\Testapp\api\test物理路径:C:\inetpub\wwroot\Testapp\api\test
  • Login method: Anonymous登录方式:匿名
  • User login: Anonymous用户登录:匿名

Most likely causes:最可能的原因:

  • The specified directory or file does not exist on this web server.此 Web 服务器上不存在指定的目录或文件。
  • The URL contains a spelling error. URL 包含拼写错误。
  • Access to the file is restricted by a custom filter or module such as URLScan.对该文件的访问受到自定义过滤器或模块(如 URLScan)的限制。

But if I run the app in the console via dotnet Testapp.dll , then it is started and if I then enter the URL http://localhost:5000/api/test in the browser, then I get the data.但是,如果我通过dotnet Testapp.dll在控制台中运行该应用程序,那么它就会启动,然后如果我在浏览器中输入 URL http://localhost:5000/api/test,我就会得到数据。

So it can only be that something has gone wrong with the IIS App setup.所以只能是IIS App设置出了问题。 By the way I also have ASP.NET Core 7.0 Runtime (v7.0.1) - Windows Hosting Bundle installed.顺便说一下,我还安装了ASP.NET Core 7.0 Runtime (v7.0.1) - Windows Hosting Bundle When setting up the app on IIS I used the following guide: http://www.technical-recipes.com/2018/running-asp-net-web-api-services-in-iis/在 IIS 上设置应用程序时,我使用了以下指南: http ://www.technical-recipes.com/2018/running-asp-net-web-api-services-in-iis/

Can anyone help me with any suggestions?谁能帮我提出任何建议?

Thanks谢谢

EDIT编辑

Following Lex's suggestion (see his comment below), I installed the Jexus Manager software and ran diagnostics.按照 Lex 的建议(请参阅下面他的评论),我安装了 Jexus Manager 软件并运行了诊断程序。 Here is the report:这是报告:


IMPORTANT: This report might contain confidential information.重要提示:本报告可能包含机密信息。 Mask such before sharing with others.在与他人分享之前掩盖这些。

System Time: 15.12.2022 10:18:45 Processor Architecture: AMD64 OS: Microsoft Windows NT 10.0.17763.0 Server Type: IIS系统时间:15.12.2022 10:18:45 处理器架构:AMD64 操作系统:Microsoft Windows NT 10.0.17763.0 服务器类型:IIS

Scan 28 installed module(s).扫描 28 个已安装的模块。 ASP.NET Core module version 2 is installed for .NET Core 3.1 and above: C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll (17.0.22323.1). .NET Core 3.1 及更高版本安装了 ASP.NET Core 模块版本 2:C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll (17.0.22323.1)。

Scan 44 registered handler(s).扫描 44 个注册处理程序。 No valid ASP.NET Core handler is registered for this web site.没有为此网站注册有效的 ASP.NET Core 处理程序。 To run ASP.NET Core on IIS, please refer to https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index for more details.要在 IIS 上运行 ASP.NET Core,请参阅https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index了解更多详细信息。

EDIT 2编辑 2

I am getting a little closer to the issue.我离这个问题越来越近了。 The fundamental error was that I used the app files from the release folder and not from Publish!根本错误是我使用了发布文件夹中的应用程序文件,而不是发布文件夹中的应用程序文件!

I have now copied the app correctly and when I start the app in IIS, browser opens and I can request the data via the Api link, So locally on the server it works.我现在已经正确复制了该应用程序,当我在 IIS 中启动该应用程序时,浏览器打开,我可以通过 Api 链接请求数据,因此它在服务器本地工作。 the problem I have now is that it does not work from external: I get the message:我现在遇到的问题是它不能从外部工作:我收到消息:

ERR_CONNECTION_TIMED_OUT ERR_CONNECTION_TIMED_OUT

The message also appears in the MAUI application which should use this web api: A connection attempt failed because the connected party did not respond properly after a period of time, or established connection failed because connected host has failed to respond.该消息还出现在应该使用此 Web API 的 MAUI 应用程序中:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应。 (api.website.com:64500) (api.website.com:64500)

I started Diagnostic Tool again and I get the following output:我再次启动诊断工具,得到以下输出:


IMPORTANT: This report might contain confidential information.重要提示:本报告可能包含机密信息。 Mask such before sharing with others.在与他人分享之前掩盖这些。

  • System Time: 15.12.2022 10:33:27系统时间:15.12.2022 10:33:27

  • Processor Architecture: AMD64处理器架构:AMD64

  • OS: Microsoft Windows NT 10.0.17763.0操作系统:Microsoft Windows NT 10.0.17763.0

  • Server Type: IIS服务器类型:IIS

  • Scan 28 installed module(s).扫描 28 个已安装的模块。

  • ASP.NET Core module version 2 is installed for .NET Core 3.1 and above: C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll (17.0.22323.1). .NET Core 3.1 及更高版本安装了 ASP.NET Core 模块版本 2:C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll (17.0.22323.1)。

Scan 45 registered handler(s).扫描 45 个注册处理程序。

  • Found a valid ASP.NET Core handler as { Name: aspNetCore, Path: *, - State: Enabled, Module: AspNetCoreModuleV2, Entry Type: Local }.找到一个有效的 ASP.NET Core 处理程序作为 { 名称:aspNetCore,路径:*,- 状态:已启用,模块:AspNetCoreModuleV2,条目类型:本地}。 Visual C++ runtime is detected (expected: 14.0, detected: 14.24.28127.4 built by: vcwrkspc): C:\Windows\system32\msvcp140.dll.检测到 Visual C++ 运行时(预期:14.0,检测到:14.24.28127.4 构建者:vcwrkspc):C:\Windows\system32\msvcp140.dll。 The application pool 'WebApplication1' is used.使用应用程序池“WebApplication1”。 Pool identity is IIS AppPool\WebApplication1 Please ensure pool identity has read access to the content folder C:\inetpub\wwwroot\WebApplication1.池标识是 IIS AppPool\WebApplication1 请确保池标识具有对内容文件夹 C:\inetpub\wwwroot\WebApplication1 的读取访问权限。 Pool bitness is 64 bit Scan aspNetCore section.池位数是 64 位扫描 aspNetCore 部分。 "processPath": dotnet. “进程路径”:点网。 "arguments": .\WebApplication1.dll. “参数”:.\WebApplication1.dll。 "hostingModel": inprocess. “hostingModel”:进程中。
  • In-process hosting model is detected.检测到进程内托管模型。 To avoid 500.xx errors, make sure that the bitness of published artifacts matches the application pool bitness Framework dependent deployment is detected.为避免 500.xx 错误,请确保已发布工件的位数与检测到的应用程序池位数相匹配 依赖于框架的部署。 Skip bitness check.跳过位数检查。 Found runtime config file C:\inetpub\wwwroot\WebApplication1\WebApplication1.runtimeconfig.json.找到运行时配置文件 C:\inetpub\wwwroot\WebApplication1\WebApplication1.runtimeconfig.json。 Runtime is 7.0.0.运行时为 7.0.0。

Now it works.现在可以了。 If someone else has similar problems (Minimal Api application under NET 7 on IIS), then here are a few tips:如果其他人有类似的问题(IIS上NET 7下的Minimal Api application),那么这里有几个提示:

  • if you release the application, you have to do it via Publish (because eg also Web-Config is under Release not generated)如果您发布应用程序,则必须通过 Publish 进行(因为例如 Web-Config 也在 Release not generated 下)
  • .NET Core Hosting Bundle must be installed on the IIS server. .NET Core Hosting Bundle 必须安装在 IIS 服务器上。
  • make sure to open the required ports under Firewall, otherwise external access is not possible确保在防火墙下打开所需的端口,否则无法进行外部访问
  • if there should be problems then it makes sense to install the app Jexus Manager and use diagnostic tool in the app.如果出现问题,那么安装应用程序 Jexus Manager 并在应用程序中使用诊断工具是有意义的。

So, hope I have not missed anything.所以,希望我没有错过任何东西。

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

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