Azure函数错误: "The Application could not be found"

标签 azure azure-functions

下午好,

我开发了一个 Azure Function,但在 Azure 环境中运行它时,出现以下错误:{"error":{"message":"找不到应用程序","code":"ApplicationNotFoundError ","correlationId":"blabla-blabla-bla-blablablabla"}}

这是我的代码:

[FunctionName("GetOperationData")]
    public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
    ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string id = req.Query["id"];

        var applicationInsightsAppId = "blablabla-blablaba-blabla-blablalbla";  
        var apiKey = "thisIsMySecret";  

        httpClient.DefaultRequestHeaders.Add("x-api-key", apiKey);

        var query = $@" requests
            | where id == '{id}'                 
            | join kind=inner (exceptions) on operation_Id
            | join kind=inner (dependencies) on operation_Id
            | join kind=inner (traces) on operation_Id
            | project id, name, url, success, resultCode, 
                      operation_Name, operation_Id, client_Type,
                      client_IP, client_City, client_StateOrProvince";


        var content = new StringContent(JsonConvert.SerializeObject(new { query = query }),
            Encoding.UTF8, "application/json");

        var response = await httpClient.PostAsync($"https://api.applicationinsights.io/v1/apps/{applicationInsightsAppId}/query"
            , content);

        var responseString = await response.Content.ReadAsStringAsync();
        return new OkObjectResult(responseString);
    }

这是错误:

enter image description here enter image description here

我检查了所有配置,似乎一切正常,所以我的角色是贡献者。

有人可以帮我吗?

提前致谢!

最佳答案

我使用了您的代码并得到了预期的结果

代码:

using  System;
using  System.IO;
using  System.Threading.Tasks;
using  Microsoft.AspNetCore.Mvc;
using  Microsoft.Azure.WebJobs;
using  Microsoft.Azure.WebJobs.Extensions.Http;
using  Microsoft.AspNetCore.Http;
using  Microsoft.Extensions.Logging;
using  Newtonsoft.Json;
using  System.Net.Http;
using  System.Text;
using  System.Net.Http.Headers;

namespace  Company.Function
{
public  static  class  TestFunction01
{
[FunctionName("GetOperationData")]
public  static  async  Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route  =  null)] HttpRequest  req,
ILogger  log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

string  id  =  req.Query["id"];  

var  applicationInsightsAppId  =  "*********";
var  apiKey  =  "******************";  

HttpClient  client  =  new  HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", apiKey); 

var  query  =  $@" requests
| where id == '{id}'                 
| join kind=inner (exceptions) on operation_Id
| join kind=inner (dependencies) on operation_Id
| join kind=inner (traces) on operation_Id
| project id, name, url, success, resultCode,
operation_Name, operation_Id, client_Type,
client_IP, client_City, client_StateOrProvince";

var  content  =  new  StringContent(JsonConvert.SerializeObject(new { query  =  query }),
Encoding.UTF8, "application/json");

var  response  =  await  client.PostAsync($"https://api.applicationinsights.io/v1/apps/{applicationInsightsAppId}/query"
, content);

var  responseString  =  await  response.Content.ReadAsStringAsync();
return  new  OkObjectResult(responseString);
}
}
}

输出:

enter image description here

enter image description here

当我在代码中将 applicationInsightsAppId 的值更改为不正确的值时,我开始收到错误消息。

enter image description here

确保您使用正确的 applicationInsightsAppIdapiKey 值。

关于Azure函数错误: "The Application could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76827780/

相关文章:

azure - 如何通过 sasTokenUri 连接 Azure Blob 存储?

asp.net - 解决 Azure 应用服务中的 .NET TypeLoadException

c# - 如何在 Azure Functions 中使用 NuGet 包?

azure - 如何重写通过 Azure blob 和 CDN 托管的静态站点的 URL?

azure - 为映射中的每个值创建资源

rest - 使用 Rest 获取所有 Azure RM VM 的状态

Azure函数应用程序Http重定向

azure - 我应该如何组织具有多个 Azure Functions 的解决方案?

Azure Function Docker 无法使用 http 触发器

javascript - Azure Functions - 值不能为空。 (参数 'connectionString')