简体   繁体   English

.Net 核心应用程序与 EXE 一起运行但不在 IIS 上运行

[英].Net core app runs with EXE but does not run on IIS

I have a.Net Core 6 app which runs fine locally, it also runs fine when I manually start the exe in the publish folder.我有一个在本地运行良好的 .Net Core 6 应用程序,当我手动启动发布文件夹中的 exe 时它也运行良好。

However when I run on IIS, it gives the following error.但是,当我在 IIS 上运行时,它会出现以下错误。

在此处输入图像描述

The server is an AWS EC2 server, I have all ports open as a test as incoming on the firewall, I have also tried to disable the firewall completely and also allowing the app through the firewall.该服务器是 AWS EC2 服务器,我将所有端口打开作为防火墙上的传入测试,我还尝试完全禁用防火墙并允许应用程序通过防火墙。 As far as I'm aware there is no AV on the EC2 instance.据我所知,EC2 实例上没有 AV。

I have added the .net core 6 runtime and I have also installed the .NET Core hosting bundle found here:我添加了 .net 核心 6 运行时,我还安装了 .NET 核心托管包,可在此处找到:

https://do.net.microsoft.com/en-us/download/do.net/6.0 https://do.net.microsoft.com/en-us/download/do.net/6.0

When I have checked the event viewer logs I get this error message:当我检查事件查看器日志时,我收到此错误消息:

Application: WebApi.exe应用程序:WebApi.exe
CoreCLR Version: 6.0.222.6406 CoreCLR 版本:6.0.222.6406
.NET Version: 6.0.2 .NET 版本:6.0.2
Description: The process was terminated due to an unhandled exception.说明:进程因未处理的异常而终止。
Exception Info: System.IO.IOException: Failed to bind to address http://localhost:4000.异常信息:System.IO.IOException:无法绑定到地址 http://localhost:4000。

System.AggregateException: One or more errors occurred. System.AggregateException:发生一个或多个错误。 (An attempt was made to access a socket in a way forbidden by its access permissions.) (An attempt was made to access a socket in a way forbidden by its access permissions.) (试图以其访问权限禁止的方式访问套接字。)(试图以其访问权限禁止的方式访问套接字。)

System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions. System.Net.Sockets.SocketException (10013):尝试以访问权限禁止的方式访问套接字。

at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException (SocketError error, String callerName)在 System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError 错误,String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)在 System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)在 System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint endpoint) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind() at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint endPoint, ConnectionDelegate connectionDelegate, EndpointConfig endpointConfig, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<g__OnBind|0>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context, CancellationToken cancellationToken) at Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostList在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint 端点)在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.TransportManager.BindAsync(EndPoint 端点,ConnectionDelegate connectionDelegate,EndpointConfig endpointConfig,CancellationToken cancellationToken)在 Microsoft.AspNetCore.Server.Kestrel .Core.KestrelServerImpl.<>c__DisplayClass30_0`1.<g__OnBind|0>d.MoveNext() --- 上一位置的堆栈跟踪结束 --- 在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync (ListenOptions 终结点、AddressBindContext 上下文、CancellationToken cancellationToken)位于 Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostList enOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken) --- End of inner exception stack trace --- enOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken) --- 内部异常堆栈跟踪结束 ---

I have read there is a setting on old versions of.NetCore to specify the use of IIS, but I can't see one for.Net Core 6.我读过旧版本的 .NetCore 上有一个设置指定使用 IIS,但我看不到 .Net Core 6 的设置。

I am pulling my hair out trying to figure out what is wrong.我正在拔头发试图找出问题所在。

Here is what is shown when I run the exe on it's own, which is correct.这是我自己运行 exe 时显示的内容,这是正确的。

在此处输入图像描述

I have finally found the reason.我终于找到了原因。

It was due to my program.cs file having this line at the bottom:这是由于我的 program.cs 文件底部有这一行:

app.Run("http://localhost:4000");

I changed this to the following and changed the port to 5000 on IIS and it all started working我将其更改为以下内容并将端口更改为 IIS 上的 5000 并且一切都开始工作

app.Run();

暂无
暂无

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

相关问题 将 .NET 核心应用程序从 Google App Engine 迁移到 Google Cloud Run - SQL 连接问题 - Migrate .NET Core app from Google App Engine to Google Cloud Run - SQL connection issues ASP.NET Cloud Run 上的 Core 6 应用未将日志路由到 Cloud Logging - ASP.NET Core 6 app on Cloud Run not routing logs to Cloud Logging ASP.NET 核心应用程序在尝试发布到 Azure 后不使用 appsettings.json 中的设置 - ASP.NET Core app does not use setting from the appsettings.json, after trying to publish to Azure AWS Fargate 如何处理其中托管的 ASP.NET Core 应用程序的健康状况? - How does AWS Fargate handle the health status of ASP.NET Core app hosted in it? 从ASP.NET Core访问Azure App Service ConnectionString - Access Azure App Service ConnectionString from ASP.NET Core Azure App Service .NET Core 3.1 导出到文件异常 - Export To File Exception in Azure App Service .NET Core 3.1 AWS Greengrass lambda 是否支持 .Net 核心运行时? - Does AWS Greengrass lambda support for .Net core runtime? 将 Asp.net 核心 mvc 应用程序从 visual studio 重新发布到 azure 应用程序服务是否会生成指向实时网站的新链接或与以前的链接相同? - Does republishing Asp.net core mvc app from visual studio to azure app service generate a new link to live website or same as previous? .NET 5 ASP.NET 核心应用程序未在 Azure 中启动 - .NET 5 ASP.NET Core App not starting in Azure Ruby on Rails 应用仅以 root 用户身份运行,以 ec2-user 身份运行时出错 - Ruby on Rails app runs only as a root user and errors out when run as ec2-user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM