我正在从HttpHandler渲染自定义用户控件,如:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string workName = context.Request.QueryString["name"];
string workForm = RenderView("~/work/" + workName + ".ascx");
context.Response.Write(workForm);
}
public static string RenderView(string path)
{
Page pageHolder = new Page();
UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
pageHolder.Controls.Add(viewControl);
StringWriter result = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, result, false);
return result.ToString();
}
问题是呈现的页面会生成一个新会话。 (我可以通过将呈现的HTML的会话ID与当前会话ID进行比较来判断)
如何让动态页面使用当前会话?
注意:代码不在登录后面,但将来会有。我是否应该记住提供会话和身份验证cookie等问题?