[英]Why I get Internal Server Error after publishing Azure Function?
I've made an API in Azure Functions that uses an Azure Sql database.我在使用 Azure Z139C4883EB4FFFF9AZ 数据库的 Azure 函数中创建了 API。 I have this route:我有这条路线:
[FunctionName("GetAllClassesForTeacher")]
public IActionResult GetAllClassesForTeacher(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req,
ILogger log)
{
var headers = req.Headers;
if (headers.TryGetValues("TeacherId", out var Teacher))
{
int TeacherId = Convert.ToInt32(Teacher.First());
var result = _classDistributionServices.GetAllClassesForTeacher(TeacherId);
if (result != null)
{
return new OkObjectResult(result);
}
return new NotFoundResult();
}
return new NotFoundResult();
}
When tested localy, it works everytime.在本地测试时,它每次都有效。 But after publishing it on Azure Portal, I get back from postman:但在 Azure 门户上发布后,我从 postman 回来:
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "f98c4112-0c31-4841-99a5-c79dffa41d86"
What I've tried/did until now:到目前为止我尝试过/做过的事情:
But still the error persists.但错误仍然存在。 I have a feeling that is still because of database firewall even if I've registered the right IP?我有一种感觉,即使我注册了正确的IP,还是因为数据库防火墙?
Can you please help me?你能帮我么?
There a few way for you to figure out what is the problem:有几种方法可以让您找出问题所在:
1-Enable Application Insights and use the Live Metrics to capture the error 1-启用 Application Insights 并使用实时指标来捕获错误
2-Use Kudu and check for more details about the error (eg https://myfunctionapp.scm.azurewebsites.net/azurejobs/#/functions ) 2-使用 Kudu 并检查有关错误的更多详细信息(例如https://myfunctionapp.scm.azurewebsites.net/azurejobs/#/functions )
3-You can also wrap your code with a try/catch and throw details of the exception in the response output. 3-您还可以使用 try/catch 包装您的代码,并在响应 output 中抛出异常的详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.