![](/img/trans.png)
[英]Upload large file - 502 bad gateway error on Azure App Service
[英]502 Error: Bad Gateway on Azure App Service with IronPDF
我正在嘗試讓 IronPDF 處理我的 ASP.NET 核心 3.1 應用服務的部署。 我沒有使用 Azure 函數,只是 Azure 應用程序服務上的常規端點 - 當用戶調用它時,服務會生成並返回生成的 ZBCD1B68617759B1DFCFF0403A6B 文檔
在 localhost 上運行端點時,它可以完美運行——從傳遞給方法的 HTML 生成報告。 但是,一旦我將它部署到我的 Azure Web 應用程序服務,我收到一個502 - Bad Gateway錯誤,如附件所示(為了簡潔起見,顯示在 Swagger 中)。
Controller:
[HttpPost]
[Route("[action]")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> AgencyDownload([FromBody] AgencyReportSubmissionDto filters)
{
var user = await _userService.GetUserByIdAsync(HttpContext.User.GetUserId());
// Generate the PDF
var content = await _agencyReport.Generate(user, null, filters.FilterDate, filters.Content, filters.Type);
// Return the PDF to the browser
return new FileContentResult(content.BinaryData, "application/pdf") { FileDownloadName = "report.pdf" };
}
服務:
public async Task<PdfDocument> Generate(User user, byte[] letterhead, DateTimeOffset filterDate, string html, AgencyReportTypes reportType)
{
var corporateIdentity = new CorporateIdentity()
{
PrimaryColor = "#000000",
PrimaryTextColor = "#ffffff",
SecondaryColor = "#ffffff"
};
// Inserts the HTML content (from form) into the HTML template
var htmlContent = Template(corporateIdentity.PrimaryColor, corporateIdentity.PrimaryTextColor).Replace("{{HtmlContent}}", html);
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("South Africa Standard Time");
var convertedDate = TimeZoneInfo.ConvertTimeFromUtc(filterDate.UtcDateTime, tz);
var Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.Title = "Agency Report - for " + convertedDate.ToString("d MMMM yyyy");
Renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
var doc = await Renderer.RenderHtmlAsPdfAsync(htmlContent);
return doc;
}
解決方案:
我注意到,如果我對該應用程序服務執行手動部署,它就可以工作,但是當我從管道進行部署時,我遇到了上述錯誤。
所以我去窺探我的管道,然后把它改成這個,它起作用了。
- task: AzureRmWebAppDeployment@4
displayName: Deploy API Artifact
inputs:
ConnectionType: 'AzureRM'
AzureSubscription: 'My-Azure-Subscription'
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
deployToSlotOrASE: true
SlotName: 'development'
AppType: 'webApp'
WebAppName: 'my-api'
Package: '$(Pipeline.Workspace)/**/API.zip'
ResourceGroupName: 'MyResource'
'DeploymentType: 'zipDeploy'”是關鍵。
感謝 Alex Hanneman 為我指明了正確的方向。
應用服務在沙盒中運行您的應用,大多數 PDF 庫將失敗。 查看IronPDF 文檔,他們說您可以在 VM 或容器中運行它。 由於您已經在使用應用服務,只需 package 將您的應用放在容器中,將其發布到容器注冊表並配置應用服務以運行它。
我還使用 Azure 應用服務作為 API,包裝 IronPDF。 升級到最新的 Iron PDF package 也破壞了我的應用程序,返回 502。
What I did to fix it is deploy the code using ZipDeploy and then set WEBSITE_RUN_FROM_PACKAGE to 0. This is also needed to get the Iron PDF log files to show up in Azure, as they recommend here: https://iron.helpscoutdocs.com /article/122-azure-log-files 。
我們也面臨與鐵 PDF 相同的問題,但是在將部署類型更改為 zip 時,它解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.