【发布时间】:2021-10-21 04:59:25
【问题描述】:
我对这个主题很陌生,但我已经使用 .Net 5 编写了一个 ASP.NET Core Web API。这个 API 只是读取和写入值到 Azure DB。它在我的机器上运行良好,但在上传/发布到 Azure 后,我收到“500 - 内部服务器错误”
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "15ed7068-cb40-4e79-8205-cc4c6d4be8be"
}
我已按照 Microsoft Doc 发布我的 API:https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0
一旦我到达步骤https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0,它就不再起作用了。这是跟踪:
api-inspector (0.238 ms)
{
"request": {
"method": "GET",
"url": "http://xxx.azure-api.net/v1/Tests",
"headers": [
{
"name": "sec-ch-ua",
"value": "\"Chromium\";v=\"92\",\" Not A;Brand\";v=\"99\",\"Google Chrome\";v=\"92\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": ""
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Sec-Fetch-Dest",
"value": "empty"
},
{
"name": "X-Forwarded-For",
"value": "xxx.xxx.xxx.xxx"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en,de;q=0.9,en-US;q=0.8,it;q=0.7,it-IT;q=0.6,und;q=0.5"
},
{
"name": "Host",
"value": "xxx.azure-api.net"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/"
}
]
}
}
api-inspector (0.003 ms)
{
"configuration": {
"api": {
"from": "/v1",
"to": {
"scheme": "https",
"host": "xxx.azurewebsites.net",
"port": 80,
"path": "/",
"queryString": "",
"query": {},
"isDefaultPort": false
},
"version": null,
"revision": "1"
},
"operation": {
"method": "GET",
"uriTemplate": "/Tests"
},
"user": "-",
"product": "-"
}
}
cors (0.020 ms)
"Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
Backend
(25.737 ms)↑ Back to top
forward-request (0.093 ms)
{
"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://xxx.azurewebsites.net:80/Tests",
"headers": [
{
"name": "Host",
"value": "xxx.azurewebsites.net:80"
},
{
"name": "sec-ch-ua",
"value": "\"Chromium\";v=\"92\",\" Not A;Brand\";v=\"99\",\"Google Chrome\";v=\"92\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": ""
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Sec-Fetch-Dest",
"value": "empty"
},
{
"name": "X-Forwarded-For",
"value": "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en,de;q=0.9,en-US;q=0.8,it;q=0.7,it-IT;q=0.6,und;q=0.5"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/"
}
]
}
}
forward-request (25.643 ms)
{
"messages": [
"The underlying connection was closed: An unexpected error occurred on a send.",
"Error occured while calling backend service.",
"The handshake failed due to an unexpected packet format."
]
}
我已经尝试过制作一个全新的项目并重新发布该项目,但没有成功。
【问题讨论】:
-
看起来 JSON 的最后几行描述了正在发生的错误。但它缺少关于位置的详细信息(例如堆栈跟踪)。您是否考虑过在您的应用程序中实施适当的异常日志记录以便获取这些详细信息?
-
您能否关注the steps in this post,并在您的问题中更新更多错误详情。
标签: c# azure asp.net-core azure-web-app-service asp.net-core-webapi