I am trying to print a web page at the default printer on the web server. I found the holy grail and it works but prints the login page not the target page, which makes sense because the controller requires auth using the asp.net membership with stock setup. I found this writeup where it is mentioned that you can use the dom interfaces if using forms auth (think that's me) but I'm not sure how to do that. It sounds like that would let the browser hit the login page and post the username/password back to finally hit the target page? Any insight on the best way to proceed would be very helpful, I would not have imagined it would be this involved to print a page that is already rendered (although printing server side it does kinda make sense). Thanks!
Edit: This works: (apparently cookie is the one thing you cannot set in the browser.Navigate method call)
HttpCookie cookie = Request.Cookies[".ASPXAUTH"];
InternetSetCookie(htmlPath, ".ASPXAUTH", cookie.Value);
browser.Navigate(htmlPath);
while (browser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
dynamic ie = browser.ActiveXInstance;
ie.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION);
and separately:
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetSetCookie(string lpszUrl, string lpszCookieName, string lpszCookieData);
This could be further improved using your code to get the forms cookie specifically instead of by name as my code.