I'm trying to save a Http Reponse into a Session variable, but I get this error
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
private System.Web.HttpResponse _response;
Function1()
{
Response.ContentType = "application/vnd.ms-excel";
string attachment = "attachment; filename=Prac_Query_Report.xls";
//Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
//Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
//ctl.RenderControl(htextw);
_response = (System.Web.HttpResponse)Session["hi"];
_response.Write(stw.ToString());
FileInfo fi = new FileInfo(Server.MapPath("~/Stylesheets/Styles1.css"));
System.Text.StringBuilder sb = new System.Text.StringBuilder();
StreamReader sr = fi.OpenText();
while (sr.Peek() >= 0)
{
sb.Append(sr.ReadLine());
}
sr.Close();
Response.Write("<html><head><style type='text/css'>" + sb.ToString() + "</style>" + stw.ToString() + "</head></html>");
stw = null;
htextw = null;
}
Function2()
{
Response.Write(footerBuilder.ToString());
Session["hi"] = Response;
}