Cookies
using IronPdf;

// Instantiate ChromePdfRenderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

renderer.RenderingOptions.RequestContext = IronPdf.Rendering.RequestContexts.Global;

ChromeHttpLoginCredentials credentials = new ChromeHttpLoginCredentials()
{
    NetworkUsername = "testUser",
    NetworkPassword = "testPassword"
};
string uri = "http://localhost:51169/Invoice";

// Apply cookies
renderer.ApplyCookies(uri, credentials);
NuGet Download
PM > Install-Package IronPdf
Cookies

Cookies

此程式碼示範如何使用IronPDF通過網路憑證認證請求並應用Cookie來將網頁渲染為PDF。

  • ChromePdfRenderer:用於將HTML內容渲染成PDF格式。
  • RequestContexts.Global:確保PDF渲染在處理流程的生命週期中保持相同的瀏覽上下文,從而使請求之間可以使用Cookie和身份驗證。
  • ChromeHttpLoginCredentials:在存取需要登錄憑證的網頁時提供網路身份驗證。
  • ApplyCookies:將指定的Cookie和憑證應用於HTTP請求,對於渲染安全頁面至關重要。
  • uri:表示需要渲染成PDF的頁面的網路地址,通常需要使用者身份驗證。 在此範例中,它指向本地託管的網頁。

此設置特別有利於從需使用者身份驗證的頁面渲染PDF,例如發票、報告或儀表板。

學習如何在使用IronPDF渲染PDF時應用Cookie。
在GitHub上查看

準備開始了嗎?

Nuget Downloads 21,916,531版本:2026.11剛剛發布