重写ASP.NET页面输出 [英] Rewrite ASP.NET page output

查看:75
本文介绍了重写ASP.NET页面输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个小背景:我试图创建使用高条纹下来ASP.NET实现一个轻量级的Cookie的数据库支持的用户会话。这个网站的观众将通过网络的元胞连接的移动用户,所以页面大小需要非常小的。我不使用.NET会话视图状态等,并且大部分网页包含很少的,如果任何服务器控件。

A little background: I am trying to create a lightweight cookieless database-backed user session using a highly striped down ASP.NET implementation. This site audience will be mobile users connecting via celluar networks, so the page sizes need to be very small. I am not using the .NET session, viewstate, etc. and most page contain very few if any server controls.

我希望能够处理一个页面请求的输出,所以我可以修改我自己的会话信息的响应内在联系。我已阅读,有一个ISAPI筛选器允许Cookie会话pre-ASP.NET。这基本上是我想建立,就在应用里面是什么。

I want to be able to process the output of a page request so I can modify internal links in the response with my own session information. I have read that there was an ISAPI filter to allow cookieless sessions pre-ASP.NET. That is basically what I want to build, just inside the application.

有没有人做过这样的事?我已经inheiriting的System.Web.UI.Page类为我的网页基础的其他原因。好像我应该能够在这里做一些事情。

Has anyone done anything like this? I'm already inheiriting the System.Web.UI.Page class for my page base for other reasons. It seems like I should be able to do something from here.

感谢

推荐答案

的HttpModules可以给你完全控制你的输出,但也有一些其他的事情可以做,这是有点简单。

HttpModules can give you complete control over your output, but there are also a couple other things you can do that are a little simpler.


  1. 创建用于Response.Filter自定义过滤器。或多或少您创建通过其发送到底层流之前,让你让你改变那里运行一切流。

  1. Create a custom Filter for the Response.Filter. More or less you create a Stream that you run everything through before sending it onto the underlying stream letting you make your changes there.

忽略网页渲染事件并编写所有内容保存到一个字符串,然后进行更改有...例如...

Override the render event for the Page and write all your contents to a string and then make your changes there... for example...

//this is from memory, you might need to check it
override void Render(HtmlTextWriter writer) {

StringWriter html = new StringWriter();
HtmlTextWriter render = new HtmlTextWriter(html);
base.Render(render);
string output = html.ToString()

//make your changes to output
//output = ???

writer.Write(output);

}

这篇关于重写ASP.NET页面输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆