[英].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.6406CoreCLR 版本: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.