一.问题描述:
二.解决办法:
三.代码演示:
1.前台页面cs文件
View Code
public partial class TestPage: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnUpLoad_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(TemplateUpload.FileContent);
Session["upLoadXmlDoc"] = doc;
string url = "test.report";
Response.Redirect(url);
}
}
2.实现IHttpHandler的HttpHandler类,用来处理test.report
View Code
public class myHttpHandler:IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
String className = businessConfig.Business[context.Request.Path];
//本行将报错,提示:Object reference not set to an instance of an object.
//添加监视,得知context.Session为null
XmlDocument doc = context.Session["upLoadXmlDoc"]
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}
3.解决办法:
View Code
public class myHttpHandler:IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
String className = businessConfig.Business[context.Request.Path];
XmlDocument doc = context.Session["upLoadXmlDoc"]
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}