Question

In my website I am using ABCpdf to generate a pdf dynamically from HTML. I have two conditions:

  1. User is logged in, is shown page one and drawn page one as pdf
  2. User is not logged in shown page two and drawn page two as pdf

My code is like this:

 string url = HttpContext.Current.Request.Url.AbsoluteUri;
        Doc theDoc = new Doc();
        theDoc.AddImageUrl(url);
        theDoc.Save(HttpContext.Current.Server.MapPath("~/media/pdf/1212.pdf"));
        theDoc.Clear();

Now the problem is like this I am able to see the first page when user is logged in but when the PDF is drawn it contains not logged in page (the second page).

I am using inproc session mode to store my login details. As far as I understood even if the user is logged in, when this code executes the server returns not logged in page the request to get the HTML to render the PDF doesnt carry over the session, but creates a new one.

Can any one give me any clue?

Was it helpful?

Solution

The reason might be that the way ABCPdf works when rendering HTML is that that it is not the user who access the page to render, but the server and the server wont have the users login session, it will access the page as if you just typed the URL in the browser on the server. So when you access the page via ABCpdf it will act as though the user is not logged in.

The way I have overcome this issue in the past is to pass a encrypted query string pram to the the page and check for this on the PDF render page and change the displayed result based on that pram value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top