|
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!!!!
|
|
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!
|
|
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.
|
|
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!
|
|
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.comPassword: 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!!!!
|
|
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!
|
|
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!!
|
|
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!
|
|