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 起