.net - Azure App Service Web 应用无法连接到 vnet 中的容器实例
问题描述
我遇到了来自我们的 Azure 应用服务 Web 应用程序 (.NET Framework 4.7) 和我们在容器实例中运行的服务的连接问题。尝试建立连接时,会引发异常。启用 .NET 套接字日志记录时,我看到以下内容:
System.Net.Sockets Verbose: 0 : [4404] Entering Socket#48359280::Connect(10.0.1.4)
ProcessId=7176
DateTime=2021-02-09T08:08:14.0357422Z
System.Net.Sockets Verbose: 0 : [4404] Entering DNS::GetHostAddresses(10.0.1.4)
ProcessId=7176
DateTime=2021-02-09T08:08:14.0357422Z
System.Net.Sockets Verbose: 0 : [4404] Exiting DNS::GetHostAddresses() -> IPAddress[]#44849943
ProcessId=7176
DateTime=2021-02-09T08:08:14.0490561Z
System.Net.Sockets Verbose: 0 : [4404] Entering Socket#48359280::Connect(IPAddress[]#44849943)
ProcessId=7176
DateTime=2021-02-09T08:08:14.0490561Z
System.Net.Sockets Verbose: 0 : [4404] Entering Socket#48359280::Connect([::ffff:10.0.1.4]:7600#501859741)
ProcessId=7176
DateTime=2021-02-09T08:08:14.0490561Z
System.Net.Sockets Error: 0 : [4404] Socket#48359280::UpdateStatusAfterSocketError() - AccessDenied
ProcessId=7176
DateTime=2021-02-09T08:08:14.0658428Z
System.Net.Sockets Error: 0 : [4404] Exception in Socket#48359280::Connect - An attempt was made to access a socket in a way forbidden by its access permissions [::ffff:10.0.1.4]:7600.
ProcessId=7176
建立连接的代码是:
try
{
socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
if (socket != null)
{
socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
socket.NoDelay = noDelay;
socket.Connect(fileservername, port);
// More statements omitted ...
}
}
catch (Exception ex)
{
string message = String.Format("Cannot connect to fileserver {0} on port {1}", fileservername, port);
Debug.WriteLine(message);
Debug.WriteLine("{0}", ex.ToString());
throw new FileserverException(message, -1);
}
容器在 vnet 中运行,IP 为 10.0.1.4。使用 Kudo PowerShell 时,我能够从应用服务服务器连接到容器。使用公共 IP 时,它也可以工作。
看起来 10.0.1.4 被转换为 "::ffff:10.0.1.4" 并且与该地址建立连接不起作用。我们已将 SocketOptionName.IPv6Only 设置为 false。
不能在 Azure vnet 中使用 AddressFamily.InterNetworkV6 吗?
该代码也在本地环境中运行而没有问题。因此,我们不想包含一个检查 Azure 并仅使用 IP4 的开关。这个问题有更好的解决方案吗?
谢谢你的帮助。
解决方案
推荐阅读
- c#-4.0 - 找不到类型或命名空间 XXX(您是否缺少 using 指令或程序集引用?
- reactjs - 如何在子组件中设置变量以在 React 的父组件中使用
- vbscript - 我不知道如何让一些命令工作
- spring - 如何将相同的前缀与多个属性类绑定
- python-3.x - LeetCode #179:最大数需要帮助理解
- python - 在 MySQL LIKE 运算符中使用多个字段
- javascript - 返回上一个元素的按钮不像想象的那样工作
- python - 如何更改joypy joyplot y轴标签颜色
- docker - 对于中等大小的响应主体,浏览器中的 HTTP 响应时间长得可笑
- go - golang中的组装案例运行恐慌?