Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将应用程序安全组添加到Azure VM_C#_Azure_Azure Virtual Machine - Fatal编程技术网

C# 将应用程序安全组添加到Azure VM

C# 将应用程序安全组添加到Azure VM,c#,azure,azure-virtual-machine,C#,Azure,Azure Virtual Machine,我需要将现有ASG(应用程序安全组)添加到现有NetworkInterface 在下面的代码中,我可以找到我的ASG和NetworkInterface。。。但我不知道如何将它们连接在一起 public void AddASG(string servername, string ASGName) { IAzure azure = ConnectAzure(); var ASG = azure.ApplicationSecurityGroups.List().Where(y =>

我需要将现有ASG(应用程序安全组)添加到现有NetworkInterface

在下面的代码中,我可以找到我的ASG和NetworkInterface。。。但我不知道如何将它们连接在一起

public void AddASG(string servername, string ASGName)
{
    IAzure azure = ConnectAzure();
    var ASG = azure.ApplicationSecurityGroups.List().Where(y => y.Name == ASGName).First();

    var nic = azure.NetworkInterfaces.List()
        .Where(y => y.Name.ToUpper().Contains(servername))
        .Select(x => x).First();

    nic.IPConfigurations?????;
}

目前似乎不可能实现这样的功能。请看一看,它还开着

作为一种解决方法,您可以发出请求,以便将所需的ASG与您的网络接口相关联

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}?api-version=2018-11-01
发送格式为的JSON请求:

 {
  "location": "xxx",
  "properties": {
    "ipConfigurations": [
    {
      "name": "primary",
      "properties": 
      {
        "privateIPAllocationMethod": "Dynamic",
        "subnet": {
          "id": "/subscriptions/xxxxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworks/xxx/subnets/xxx"
      },
        "applicationSecurityGroups" : [
          { 
            "id": "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/applicationSecurityGroups/xxx"
          }
        ]
      }
    }
    ]
 }
}
或者,你也可以


希望这能对您有所帮助。

非常感谢,我会尝试一下,但这看起来是个不错的选择