IRONSOFTWAREHOME
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);
Imports IronPdf

' Instantiate ChromePdfRenderer
Dim renderer As New ChromePdfRenderer()

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

Dim credentials As New ChromeHttpLoginCredentials() With {
    .NetworkUsername = "testUser",
    .NetworkPassword = "testPassword"
}
Dim uri As String = "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,105,021版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密。
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立
C# 用於PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. 在解決方案資源管理器,右鍵點選參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronPdf"
  3. 選擇套件並安裝
C# PDF DLL
下載DLL

版本: 2026.9

或者點擊此處下載Windows安裝程式。

  1. 下載並解壓IronPDF到類似~/Libs的位置,位於您的解決方案目錄中
  2. 在Visual Studio解決方案資源管理器,右鍵點選參考。選擇瀏覽,"IronPdf.dll"

授權從$999起