I have the following code which was ok until someone else put some other code in the site which sorta mucks it up now.
This is my code:
var existingContext = HttpContext.Current;
var writer = new StringWriter();
var response = new HttpResponse(writer);
var context = new HttpContext(existingContext.Request, response) { User = existingContext.User };
HttpContext.Current = context;
HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Default);
HttpContext.Current.Session["Test"] = "test";
for (Int32 i = 0; i < existingContext.Session.Count; i++)
{
HttpContext.Current.Session.Add(existingContext.Session.Keys[i], existingContext.Session[i]);
}
The idea behind this is to be able to capture the output of a view and render it to pdf. Now my only issue is that when i assign context back to HttpContext.Current, the session is null. I need to be able to initialize the session so that i can assign variables into it.
i will also add that this is inside a static class
public static class ControllerExtensions
Any clues?