c# - Azure Web App 引发 HTTP 错误 500.0 - 内部服务器错误 由于发生内部服务器错误,无法显示页面

标签 c# azure asp.net-web-api azure-web-app-service

我确实有一个基于 .NET Framework 应用程序的 C# ASP.NET Web API 在本地计算机上运行得非常好。但是,当我将其部署到 Azure Web App Service 并尝试访问其中一个端点时,出现错误:

The error message as received in the Application Log Stream 我不明白的是错误中的文件夹 \api\print 来自哪里?我的端点正在做两件事:

  1. 创建 PDF 文件。这工作正常,因为我可以在 wwwroot\app_data 文件夹中看到创建的文件
  2. 将创建的 PDF 文件上传到 Google 云端硬盘。这就是代码失败的地方。我怀疑是因为该应用程序无法打开该文件。

下面是上述操作的代码:

    public GoogleDrivePDFFile CreateTicket()
    {
        //directory for created files as per stakeoverflow question https://stackoverflow.com/questions/1268738.
        string tickets_path = HostingEnvironment.MapPath("~/App_Data/");

        //current date and time 
        var current_date_time = DateTime.UtcNow;

        string google_file_name = string.Concat(
             current_date_time.Year, 
             current_date_time.Month, 
             current_date_time.Day, 
             current_date_time.Hour, 
             current_date_time.Minute, 
             current_date_time.Second,
            "_", "XXXX",
            ".pdf"
           ); //the filename to use for the new created file
        
        //full path for the new file in the filesytem
        string filName = Path.Combine(tickets_path, google_file_name); 

        //file is being created okay in the filesystem. I can see it in Azure app file system.
        PdfFormatProvider provider = new PdfFormatProvider();
        using (Stream output = File.Open(filName, FileMode.CreateNew))
        {
           provider.Export(document, output);
        }

        GoogleUploads googleUploads = new GoogleUploads();

        //It is failing here.....
        var returned_file = googleUploads.UploadTicket(google_file_name, filName, requiredDocument);

        /*
         * I have tested the endpoint with the below and this works fine.
         * 
            var working_example = new GoogleDrivePDFFile();
            working_example.DocumentId = "Document ID .... okay";
            working_example.DownloadLink = "Download Link .... okay";
            working_example.WebViewLink = "Web View Link .... okay";

            return working_example;
        */

        return returned_file;
    }

我不知道我做错了什么。

最佳答案

就我而言,我的 Google 安全 key 文件未上传到 Azure Web 应用程序文件系统。这就是我的代码无法工作的原因。我上传了 key 文件并且我的应用程序运行了。

关于c# - Azure Web App 引发 HTTP 错误 500.0 - 内部服务器错误 由于发生内部服务器错误,无法显示页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73214441/

相关文章:

c# - 使用 P/Invoke 时如何将 Win32 类型映射到 C# 类型?

c# - LINQ 在哪里为它的 IEnumerable<T> 结果重载 Console.WriteLine()

azure - 个人 Microsoft 帐户的守护程序应用程序权限

azure - 无法运行Azure管道 "A task is missing. The pipeline references a task called '缓存'

c# - SQLite 与 Web 服务 c#

c# - 反序列化 JSON 并将对象保存到 MySQL 数据库

sql - 为什么没有选项使用 ssms 将数据导入到 Azure 数据库?

json - ASP.NET WebApi 4 Post FromBody 不从 JSON 绑定(bind)

c# - 查看将在 HttpResponseMessage/HttpRequestMessage (System.Net.Http, WebAPI) 中发送/接收的原始 header

c# - 如何在 ASP.NET 应用程序中序列化异常?