ASP.NET Core Web API 无法在 Azure 上运行
ASP.NET Core Web API not working on Azure
我对这个主题很陌生,但我已经使用 .Net 5 编写了一个 ASP.NET Core Web API。这个 API 只是读取和写入值到天蓝色数据库。它在我的机器上工作得很好,但是在 upload/publish 到 Azure 之后我得到一个“500 - 内部服务器错误”
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "15ed7068-cb40-4e79-8205-cc4c6d4be8be"
}
我已经按照 Microsoft 文档发布了我的 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."
]
}
我已经尝试制作一个全新的项目并重新发布那个项目,但没有成功。
我有同样的问题,我通过将端口从 80 更改为 443(如果您使用 HTTPS)解决了这个问题。希望它能帮助你。或者你可以参考这个 https://github.com/ThreeMammals/Ocelot/issues/912
我对这个主题很陌生,但我已经使用 .Net 5 编写了一个 ASP.NET Core Web API。这个 API 只是读取和写入值到天蓝色数据库。它在我的机器上工作得很好,但是在 upload/publish 到 Azure 之后我得到一个“500 - 内部服务器错误”
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "15ed7068-cb40-4e79-8205-cc4c6d4be8be"
}
我已经按照 Microsoft 文档发布了我的 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."
]
}
我已经尝试制作一个全新的项目并重新发布那个项目,但没有成功。
我有同样的问题,我通过将端口从 80 更改为 443(如果您使用 HTTPS)解决了这个问题。希望它能帮助你。或者你可以参考这个 https://github.com/ThreeMammals/Ocelot/issues/912