有没有办法使用 C# 从我的 Function App 中删除 Azure Function?

我正在尝试通过 C# 从我的函数应用程序中删除 Azure 函数。但是,在以编程方式删除它时,用户界面上看不到该函数,但是当我通过高级工具(Kudu)检查它时,我仍然可以看到我的Azure函数。

因此,基本上在删除 Azure 函数时,我所做的就是删除它的 function.json,这样 Azure 函数在函数应用程序列表中就不再可见(见下图)

https://img3.mukewang.com/64d885f90001323407670300.jpg

但是当我去Advanced Kudu检查它是否被删除时,我仍然可以看到它,但是没有function.json文件。我以前做过这个(大约 6 个月前),当时它工作正常。我不知道是我做错了还是有什么改变。

https://img4.mukewang.com/64d886000001628a08580211.jpg


达令说
浏览 85回答 1
1回答

慕仙森

您可以使用 REST API 来执行此操作。https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}?api-version=2016-08-01方法: DELETE代码片段:&nbsp;HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, string.Format("https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}?api-version=2016-08-01", "Pass All Param In {}")));&nbsp;request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", results.access_token);&nbsp;HttpResponseMessage response = await _client.SendAsync(request);&nbsp;if (response.IsSuccessStatusCode)&nbsp;{&nbsp; &nbsp; dynamic objApiResponse = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync());&nbsp;}&nbsp;else&nbsp;{&nbsp; &nbsp; return req.CreateResponse(HttpStatusCode.OK, "Sorry Invalid Request");&nbsp;}详细信息请查看官方文档注意:对于令牌请求,您resource/Scope应该是https://management.azure.com. 发送请求时传递您的令牌。更新:您可以使用身份验证流程请求令牌client_credentials。尝试以下格式:应用程序 ID 和租户 ID 的 Azure 门户凭据:来自门户的应用程序秘密:令牌端点或 URL:https://login.microsoftonline.com/YourTenantName.onmicrosoft.com/oauth2/token请求参数:grant_type:client_credentialsclient_id:b603c7be_Your_App_ID_e6921e61f925client_secret:Vxf1Sl_Your_App_Secret_2XDSeZ8wL/Yp8ns4sc=resource:https://graph.microsoft.com&nbsp;邮递员示例:令牌响应:令牌端点或 URL:https://login.microsoftonline.com/YourTenantName.onmicrosoft.com/oauth2/token请求参数:grant_type:client_credentialsclient_id:b603c7be_Your_App_ID_e6921e61f925client_secret:Vxf1Sl_Your_App_Secret_2XDSeZ8wL/Yp8ns4sc=resource:https://graph.microsoft.com&nbsp;邮递员示例:需要记住的一点:如果您遇到此错误InvalidAuthenticationToken:收到的访问令牌无效:至少应存在声明“puid”、“altsecid”或“oid”之一。如果您作为应用程序访问,请确保在租户中正确创建服务主体您必须为您的应用程序分配角色,如下所示:
打开App,查看更多内容
随时随地看视频慕课网APP