I need to acquire HTML markup of a controller/action in order to generate PDF. What I have done is:
public ActionResult Index()
{
Session["Message"] = "SESSION-MESSAGE";
String URL = "http://localhost:7401/Home/SuperComplex";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
req.CookieContainer = new CookieContainer();
for (int i = 0; i <= this.Request.Cookies.Count - 1; i++)
req.CookieContainer.Add(
new System.Net.Cookie(
name: this.Request.Cookies[i].Name,
value: Request.Cookies[i].Value,
path: Request.Cookies[i].Path, domain: this.HttpContext.Request.Url.Host)
);
using (var r = req.GetResponse())
{
using (var s = new StreamReader(r.GetResponseStream()))
{
var htmlToPrint = s.ReadToEnd();
Response.Write("<h1>" + htmlToPrint + "</h1>");
}
}
return View();
}
Considering above said situation, in SuperComplex session, I should have the Session["Message"]. But for some strange reason, it does not go there.
I have checked Session.SessionId - in both cases it is same.
Also, on second or third request, request timesout!
Again: http://localhost:7401/(S(SESSION_ID))/Home/About
If requested in other browser: session hijack does happen - but WebRequest dies! :(
Help - anyone?