Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf Authentication error Options
WMP
Posted: Tuesday, April 23, 2013 11:35:10 AM
Rank: Advanced Member
Groups: Member

Joined: 7/6/2011
Posts: 30
Hi I realise this question has been asked before but I'm stuck for ideas how to get around it. My code is working fine locally but on the server where the site is using windows authentication I'm getting the error:
Exception Details: System.Exception: EO.Pdf.HtmlToPdfException: Failed to convert Url 'http://mysite/mypage.aspx?id=33'.(401:The requested resource requires user authentication. This is an error returned by the Web server, not by the HTML to PDF converter. Please try to visit the same Url with your browser to verify whether the Url is valid.)
at EO.Pdf.Internal.de.a(String A_0, Boolean A_1)
at EO.Pdf.Internal.de.b(HtmlToPdfOptions A_0, String A_1, Boolean A_2)
at EO.Pdf.Internal.de.a(bs A_0)
at EO.Pdf.Internal.lr.c.a(Byte[] A_0)

The URL is fine, I have granted access to all users on the bin folder and url to be converted. My code is:
Code: C#
PdfDocument doc = new PdfDocument();
            HtmlToPdf.Options.PageSize = EO.Pdf.PdfPageSizes.A4;
            HtmlToPdf.Options.FooterHtmlPosition = 9.8F;
            HtmlToPdf.Options.AllowLocalAccess = true;
            HtmlToPdf.ConvertUrl(AttachmentUrl, doc);
            MemoryStream ms = new MemoryStream();
            doc.Save(ms);


Any new ideas or code suggestions would much appreciated.
eo_support
Posted: Tuesday, April 23, 2013 8:46:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,675
Hi,

When Windows authentication is required, we use the calling thread's user context to authenticate the server. So when you call the converter from your client machine, we will use the client user's user context to authenticate with the web server. However when the converter is running on the server, the server process's user context is used. If that user context does not have enough permission, then you will get access denied error.

You can try to enable impersonation and see if it works for you. When impersonation is enabled, IIS temporarily switch to the client's user context when process a request from that client. When that happens, the HTML to PDF converter will also inherits the client's user context.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
saeed
Posted: Friday, November 8, 2019 9:29:42 AM
Rank: Newbie
Groups: Member

Joined: 11/8/2019
Posts: 2
I have same problem as topic starter , i can not resolve my problem ! i have form authentication for user login.but get same error
Quote:
Server Error in '/' Application.
Conversion error: Authentication error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Conversion error: Authentication error.


May you help me about my problem ?
eo_support
Posted: Friday, November 8, 2019 10:49:48 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,675
saeed wrote:
I have same problem as topic starter , i can not resolve my problem ! i have form authentication for user login.but get same error
Quote:
Server Error in '/' Application.
Conversion error: Authentication error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Conversion error: Authentication error.


May you help me about my problem ?


You will need to find out exactly what authentication information your server want and provide it. There are different mechanisms to authenticate with the server and each mechanism requires different solutions. For example, if your form authentication relies on cookies, then you need to pass the authentication cookie to the converter in order to authenticate successfully.

Also can you PM us your license ID/order number?
saeed
Posted: Friday, November 8, 2019 11:53:38 AM
Rank: Newbie
Groups: Member

Joined: 11/8/2019
Posts: 2
I was update my controller action to this code :
Quote:
public ActionResult Convert(int id)
{

HtmlToPdf converter = new HtmlToPdf();
// converter.Options.HttpCookies.Add(
//System.Web.Security.FormsAuthentication.FormsCookieName,
// Request.Cookies[FormsAuthentication.FormsCookieName].Value);
converter.Options.Authentication.Username = "*****@gmail.com";
converter.Options.Authentication.Password = "*****";
var context = System.Web.HttpContext.Current;
//string baseUrl = context.Request.Url.Host + ":"+context.Request.Url.Port + "/Doctor/DietTherapy/LineRegimePrint/";
string baseUrl = "http://www.mehrdiet.com/Doctor/DietTherapy/LineRegimePrint/";
PdfDocument doc = converter.ConvertUrl(baseUrl+id);

// save pdf document
byte[] pdf = doc.Save();

// close pdf document
doc.Close();

// return resulted pdf document
FileResult fileResult = new FileContentResult(pdf, "application/pdf");
fileResult.FileDownloadName = "Document.pdf";
return fileResult;
}

Now i get this error :
Quote:
Server Error in '/' Application.
Conversion error: Could not open url.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Conversion error: Could not open url.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Note : Url is my site action ! if have any better way for link to action please tell me.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.