我正在尝试创建新的防火墙规则。我没有更新现有规则的问题但我无法创建新规则。我在响应中获得了真正的statusCode,但在Azure门户中看不到结果(几分钟后)。附加的代码属于Web应用程序,具有MySql组资源的专有角色。我做错了什么?
private static string URI_FIREWALL_BASE = "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/MY_RESOURCE/providers/Microsoft.DBforMySQL/servers/MYSERVER/firewallRules/";
public string AddIPFirewallRule(string email, string IP)
{
AuthenticationResult token = AsyncContext.Run(() => AzureActiveDirectory.GetS2SAccessTokenForProdMSAAsync());
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
JObject NewRule =
new JObject(
new JProperty("properties",
new JObject(
new JProperty("startIpAddress", IP),
new JProperty("endIpAddress", IP)
)));
var content = JsonConvert.SerializeObject(NewRule);
var httpContent = new StringContent(content, Encoding.UTF8, "application/json");
HttpResponseMessage resp = AsyncContext.Run(() => client.PutAsync(URI_FIREWALL_BASE + $"{email}?api-version=2017-12-01", httpContent));
return AsyncContext.Run(() => resp.Content.ReadAsStringAsync());
}
答案 0 :(得分:0)
最后我明白了。我必须遵循一些规则来命名新服务,因为您可以在Azure Portal Desktop上手动执行相同的操作。