文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用PagePaser创建Page作为HttpHandler

用PagePaser创建Page作为HttpHandler

时间:2011-01-06  来源:dragonpig

protected void Page_Load(object sender, EventArgs e)
{
Response.Write(HttpUtility.HtmlEncode(DumpHtmlFrom(
"~/Default.aspx")));
}

//virtualPath: allow queries
string DumpHtmlFrom(string virtualPath)
{
StringWriter writer
= new StringWriter();
var path
= Request.Url.Scheme + "://" + Request.Url.Authority + VirtualPathUtility.ToAbsolute(virtualPath);
var parts
= virtualPath.Split('?');

string query = string.Empty;
if (parts.Length > 1)
query
= parts[1];
virtualPath
= parts[0];

HttpContext context
= new HttpContext(new HttpRequest(virtualPath, path, query), new HttpResponse(writer));
var handler
= PageParser.GetCompiledPageInstance(virtualPath, MapPath(virtualPath), context);
handler.ProcessRequest(context);

return writer.ToString();
}

其中关键的步骤PageParser.GetCompiledPageInstance实例化了一个HttpHandler,并返回所有的Html。

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载