Search code examples
htmlformsauthenticationpdfevopdf

HTML to PDF and Forms authentication


I successfully used the EVO HTML to PDF tool in a previous project and now I'm trying to to integrate it in another project. The problem is that the page I have to convert is behind the ASP.NET forms authentication and when I convert the page I get the login form. How can I pass over forms authentication and get the page content in PDF?


Solution

  • You can use the following code to get the Forms Authentication cookie from current request and pass it to converter to be used when accessing the HTML page to convert:

    HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();
    
    // Add the Forms Authentication cookie to request
    if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
    {
        htmlToPdfConverter.HttpRequestCookies.Add(FormsAuthentication.FormsCookieName,
             Request.Cookies[FormsAuthentication.FormsCookieName].Value);
    }
    
    htmlToPdfConverter.ConvertUrl(urlToConvert);