我有一个 .Net Core 6 应用程序,它在本地运行良好,当我在发布文件夹中手动启动 exe 时,它也运行良好。
但是,当我在 IIS 上运行时,会出现以下错误。
服务器是 AWS EC2 服务器,我打开所有端口作为防火墙传入的测试,我还尝试完全禁用防火墙并允许应用程序通过防火墙。据我所知,EC2 实例上没有 AV。
我添加了 .net core 6 运行时,并且还安装了此处找到的 .NET Core 托管捆绑包:
https://dotnet.microsoft.com/en-us/download/dotnet/6.0
当我检查事件查看器日志时,我收到以下错误消息:
应用程序:WebApi.exe
CoreCLR 版本:6.0.222.6406
.NET版本:6.0.2
描述:由于未处理的异常,进程被终止。
异常信息:System.IO.IOException:无法绑定到地址http://localhost:4000。
System.AggregateException:发生一个或多个错误。 (尝试以访问权限禁止的方式访问套接字。)(尝试以访问权限禁止的方式访问套接字。)
System.Net.Sockets.SocketException (10013): 尝试以访问权限禁止的方式访问套接字。
在System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError错误,字符串callerName)
在 System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress 套接字地址)
在 System.Net.Sockets.Socket.Bind(EndPoint localEP)
在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportOptions.CreateDefaultBoundListenSocket(EndPoint 端点)
在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
在 Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint 端点,CancellationToken CancellationToken)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastruct.TransportManager.BindAsync(EndPoint endPoint、ConnectionDelegate connectionDelegate、EndpointConfig endpointConfig、CancellationToken CancellationToken)
在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.<>c__DisplayClass30_0`1.d.MoveNext()
--- 先前位置的堆栈跟踪结束 ---
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions 端点、AddressBindContext 上下文、CancellationToken CancellationToken)
在 Microsoft.AspNetCore.Server.Kestrel.Core.LocalhostListenOptions.BindAsync(AddressBindContext 上下文,CancellationToken CancellationToken)
--- 内部异常堆栈跟踪结束 ---
我读到旧版本的 .NetCore 上有一个设置来指定 IIS 的使用,但我看不到 .Net Core 6 的设置。
我正在抓狂试图找出问题所在。
这是我单独运行 exe 时显示的内容,这是正确的。
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.
However when I run on IIS, it gives the following error.
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. As far as I'm aware there is no AV on the EC2 instance.
I have added the .net core 6 runtime and I have also installed the .NET Core hosting bundle found here:
https://dotnet.microsoft.com/en-us/download/dotnet/6.0
When I have checked the event viewer logs I get this error message:
Application: WebApi.exe
CoreCLR Version: 6.0.222.6406
.NET Version: 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.AggregateException: One or more errors occurred. (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.
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException (SocketError error, String callerName)
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at 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.LocalhostListenOptions.BindAsync(AddressBindContext context, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
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.
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.
发布评论
评论(1)
我终于找到原因了。
这是因为我的program.cs文件底部有这一行:
我将其更改为以下内容,并将IIS上的端口更改为5000,一切都开始工作
I have finally found the reason.
It was due to my program.cs file having this line at the bottom:
I changed this to the following and changed the port to 5000 on IIS and it all started working