Forum How do I...?

How to avoid 401 error on images

BrianW
I've got a webpage that I'm trying to create a PDF from (MVC3 if that matters). Everything is working great except that the company logo that should be displayed isn't loading and there is a warning in the log file (warning: The requested URL returned error: 401).

When I watch the requests made using Fiddler what I see is that there are two requests made for the image file. The first one returns a status 401 and the second returns status 200 and successfully returns the file. As far as I can tell this is likely authentication related, but I'm at a loss for how to avoid it. Has anybody run into this before or have an idea on how to avoid it?
mikeday
Yes, this is authentication related. What happens if you go to the URL with a browser that isn't currently logged in to the site?
BrianW
Thanks for the reply. We had been using a mixed-mode authentication with Windows Authentication as the primary with a fallback to Forms. Since we had the removal of the Windows Auth on our to-do list anyway I went ahead and killed that which solved this problem.
mikeday
For the record, Prince 10 now has support for Windows authentication.
TomWu
Hi Mike,

We've used PrinceXml for years, It's great!

I just got similar issue from my CMS system:
The image that should be displayed isn't loading and there is a warning in the log file
(msg|wrn|http://127.0.0.1/storage/images/1234|The requested URL returned error: 401).

To access the image service, it need to pass the authentication.

It works fine to get html content from other services with --auth-user= and --auth-password=

But it doesn't work with this html tag:
<img src="/storage/images/1234" style="prince-image-resolution: 300dpi">
TomWu
Is the get image request using the --auth-user= --auth-password= which get from command line?

Is there anyway to let image request to support authentication, any suggestion?
mikeday
That should work. Can you check the Prince output log (maybe running with --verbose) and see exactly which HTTP or HTTPS URL it is trying to retrieve and confirm that it is correct?
TomWu
Thanks for your reply.

I confirmed the URL is correct since it works in web browser. I also tried to use --verbose to check the url:
(msg|wrn|http://127.0.0.1/storage/images/1234|The requested URL returned error: 401).
After login, web browser display URL http://127.0.0.1/storage/images/1234 as a image correctly.

Does the getting image request send cookie? Is it make sense If I change the command line to use user cookie?
mikeday
I think cookies are not sent to 127.0.0.1, only to named hosts like localhost. If you google for "127.0.0.1 cookies" it seems this is a common issue. I'm not sure why it is working in the browser.
TomWu
Thanks. I never get the 127.0.0.1 cookie issue, my platform is Chrome on OSX. I will try the normal domain name for it.
TomWu
It works now. It's beautiful! Thank you for your help!
In fact, there are also some issues from my system.