简体   繁体   English

为什么发布 Azure Function 后出现内部服务器错误?

[英]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:到目前为止我尝试过/做过的事情:

  • to take the IP from Azure Function and register it in Firewalls and virtual networks from Azure Sql Server. to take the IP from Azure Function and register it in Firewalls and virtual networks from Azure Sql Server.
  • I've made sure that the ConnectionString from local.settings.json it is uploaded on portal.我已确保将来自 local.settings.json 的 ConnectionString 上传到门户网站。
  • I've declared this route in API Management.我已经在 API Management 中声明了这条路线。

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.

相关问题 在服务器上工作,但发布后出现错误 - On server works but after the publishing i get an error 发布后的内部服务器错误和未创建的表 - Internal Server Error after publishing and Tables not being created 为什么我收到状态为 500 的错误(内部服务器错误) - Why I get error with status of 500 (Internal Server Error) Azure Function v2 在处理 StorageException 后始终返回内部服务器错误 500 - Azure Function v2 always returning Internal Server Error 500 after a handled StorageException 发布到服务器后,无法使用Entity Framework和Ajax发布-500内部服务器错误 - Working with Entity Framework and ajax post is not working after publishing to a server - 500 internal server error 通过IIS发布网站后,由于内部服务器错误,回调请求失败 - Callback request failed due to an internal server error after publishing a website Through IIS Azure函数:HttpTrigger和输出队列返回“内部服务器错误” - Azure function : HttpTrigger and output queue returned “Internal Server Error” Azure Function 来自 SocketException 的代理内部服务器错误 500 - Azure Function Proxy Internal Server Error 500 from SocketException 在门户中运行Azure功能时发生内部服务器错误 - Internal server Error when running Azure Function in the Portal 如何修复错误发布到 azure function - How to fix error publishing to azure function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM