Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdfSession Always Prints Login Page Options
cognitronic
Posted: Sunday, December 23, 2012 2:47:59 PM
Rank: Newbie
Groups: Member

Joined: 12/23/2012
Posts: 4
I'm evaluating your product and absolutely love the results, but I am having a hard time using the htmltopdfsession to render a secured page. 99% of the time I will need to render pages that require authentication....and most of them are forms authentication. I'm testing on a MVC 4 application and in the ActionResult of a page I'm running the following code:

Quote:
session.LoadUrl("http://hrr.localhost/Login");
session.Fill("tbUsername", "test@test.com");
session.Fill("tbPassword", "password");
session.Submit("lbLogin");
session.LoadUrl("http://hrr.localhost/comments/all");
session.RenderAsPDF("d:\\comments.pdf");


The outcome is always just the login page. Any help would be much appreciated!!!!
eo_support
Posted: Sunday, December 23, 2012 4:00:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Most likely the username, password, and login button name you passed to Fill and Submit are wrong. They are usually NOT the same as your server control ID. They should be the "name" of the corresponding form element. You can view your page HTML source and search for tbUsername, you will find the name attribute can be something much longer. For example, for our own website, the ID of the username textbox is "txtEmail", but the "name" of that textbox is "ctl00$ContentHolder$ctrlLogin$txtEmail". This long value is the value you need to pass to your Fill method and Submit method.

Thanks!
cognitronic
Posted: Sunday, December 23, 2012 8:47:08 PM
Rank: Newbie
Groups: Member

Joined: 12/23/2012
Posts: 4
Im pretty sure those are the correct ids. Here is the actual view source snippet:

Quote:
<div>
<div style="margin-bottom: 3px;">Username</div>
<span id="tbUsername_wrapper" class="riSingle RadInput RadInput_Windows7" style="width:310px;"><input id="tbUsername" name="tbUsername" size="20" class="riTextBox riEnabled" type="text" /><input id="tbUsername_ClientState" name="tbUsername_ClientState" type="hidden" /></span>
</div><br />
<div>
<div style="margin-bottom: 3px;">Password</div>
<span id="tbPassword_wrapper" class="riSingle RadInput RadInput_Windows7" style="width:310px;"><input id="tbPassword" name="tbPassword" size="20" class="riTextBox riEnabled" type="password" /><input id="tbPassword_ClientState" name="tbPassword_ClientState" type="hidden" /></span>
</div><br />
<div style="margin-bottom: 5px;">

</div>
<div>
<span>
<input type="submit" name="lbLogin" value="Login" id="lbLogin" class="button huge round sky-blue" />
</span>
<span>
<input type="submit" name="lbForgotPassword" value="Forgot Password?" id="lbForgotPassword" class="button huge round sky-blue" />
</span>
</div>




Your website has that name schema because your controls are nested inside a master page panel, but my login page does not use a master page or any panels.

eo_support
Posted: Sunday, December 23, 2012 8:51:39 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Then it should work. If it still does not work, you can put the site online and we will be able to run the code from here, then trace the HTTP traffic to find out why.

Thanks!
cognitronic
Posted: Sunday, December 23, 2012 9:17:23 PM
Rank: Newbie
Groups: Member

Joined: 12/23/2012
Posts: 4
you can test it online now. The url is http://beta.hrriver.com. Use the following credentials:

Username: jet@hrriver.com
Password: password

Let me know what you find and when you're finished so I can reset the password. Thank you SO much for your help!!!!
eo_support
Posted: Sunday, December 23, 2012 10:08:21 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Please try the following code:

Code: C#
session.LoadUrl("https://beta.hrriver.com/Login");
session.Fill("tbUsername", "jet@hrriver.com");
session.Fill("tbUsername_ClientState", "{\"enabled\":true,\"emptyMessage\":\"\",\"validationText\":\"jet@hrriver.com\",\"valueAsString\":\"jet@hrriver.com\"}");
session.Fill("tbPassword", "password");
session.Fill("tbPassword_ClientState", "{\"enabled\":true,\"emptyMessage\":\"\",\"validationText\":\"password\",\"valueAsString\":\"password\"}");
session.Submit("lbLogin");


Note the code that sets tbUsername_ClientState and tbPassword_ClientState. The plain value for these two variables should be:

Code: C#
{"enabled":true,"emptyMessage":"","validationText":"jet@hrriver.com","valueAsString":"jet@hrriver.com"}
{"enabled":true,"emptyMessage":"","validationText":"password","valueAsString":"password"}

Obviously Telerik code maintains these two additional variables and updates them when user types in the actual username/password input elements. When you call "Fill", it fills the form variable but does not trigger DOM event associated to keyboards such as onkeypress/onblur. Thus the corresponding Telerik script is not triggered and those two additional variables are not automatically updated. As such you have to manually fill them as well.

Hope this helps. Please let us know if this works for you.

Thanks!
cognitronic
Posted: Sunday, December 23, 2012 10:26:36 PM
Rank: Newbie
Groups: Member

Joined: 12/23/2012
Posts: 4
Fantastic, it works!! I will most definitely be purchasing this product. Not only are the results top notch, but the support might be the best I've ever had with any piece of software. Thank you for your time and help!!
eo_support
Posted: Sunday, December 23, 2012 10:31:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Glad to hear that it works for you! Please feel free to let us know if you run into any other issues.

Thanks!


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.