Understanding Kerberos in IronPDF

How can I get UrlToPdf working with Kerberos authentication?

To use Kerberos authentication with IronPDF's UrlToPdf, you should set a username and password in the rendering settings. You can refer to the IronPDF documentation for more details: IronPdf.ChromeHttpLoginCredentials.

We recommend using System.Net.Http.HttpClient for downloading HTML content, which you can render afterward. This approach allows you to handle HTTP requests, including those requiring authentication, before IronPDF processes the content.

Here is an online guide on downloading pages with Kerberos: How does the System.Net.Http.HttpClient select authentication type?. This StackOverflow link provides a detailed discussion on implementing authentication using HttpClient.

To parse and ensure that all necessary assets within the HTML are downloaded, consider using the HTML Agility Pack. This .NET library helps in manipulating and querying HTML documents effectively.

// Example: Using HttpClient with Kerberos Authentication

// Import the necessary namespaces
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace KerberosAuthenticationExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Create an instance of HttpClient
            HttpClientHandler handler = new HttpClientHandler
            {
                // Automatically use default network credentials
                UseDefaultCredentials = true // Enables Windows authentication (e.g., Kerberos)
            };

            using HttpClient httpClient = new HttpClient(handler);

            try
            {
                // Send a GET request to the desired URL
                HttpResponseMessage response = await httpClient.GetAsync("https://your-secure-url.com");

                // Ensure the request was successful
                response.EnsureSuccessStatusCode();

                // Read and display the response body
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);

                // If needed, render the HTML to PDF with IronPDF here
                // IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf();
                // renderer.RenderHtmlAsPdf(responseBody).SaveAs("output.pdf");
            }
            catch (HttpRequestException e)
            {
                // Handle any error responses from the server or connection issues
                Console.WriteLine("\nException Caught!");
                Console.WriteLine($"Message :{e.Message}");
            }
        }
    }
}
// Example: Using HttpClient with Kerberos Authentication

// Import the necessary namespaces
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace KerberosAuthenticationExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Create an instance of HttpClient
            HttpClientHandler handler = new HttpClientHandler
            {
                // Automatically use default network credentials
                UseDefaultCredentials = true // Enables Windows authentication (e.g., Kerberos)
            };

            using HttpClient httpClient = new HttpClient(handler);

            try
            {
                // Send a GET request to the desired URL
                HttpResponseMessage response = await httpClient.GetAsync("https://your-secure-url.com");

                // Ensure the request was successful
                response.EnsureSuccessStatusCode();

                // Read and display the response body
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseBody);

                // If needed, render the HTML to PDF with IronPDF here
                // IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf();
                // renderer.RenderHtmlAsPdf(responseBody).SaveAs("output.pdf");
            }
            catch (HttpRequestException e)
            {
                // Handle any error responses from the server or connection issues
                Console.WriteLine("\nException Caught!");
                Console.WriteLine($"Message :{e.Message}");
            }
        }
    }
}
$vbLabelText   $csharpLabel

Key points:

  • HttpClient and HttpClientHandler: Use HttpClientHandler with UseDefaultCredentials = true to allow Kerberos authentication using the current user's credentials.
  • Error Handling: Implement try-catch blocks to manage exceptions during HTTP requests.
  • HTML Rendering: Once the HTML is fetched, utilize IronPDF to render the content into a PDF if necessary.
Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released