Asp.net地址转义(分析)加强版--Dottext的地址分析模块的不足之处及相应的解决方案
Posted on 2006-06-24 11:11 天雪 阅读(248) 评论(0) 编辑 收藏 举报(地址转义:指像http://thinhunan.cnblogs.com/这样的地址,被转义成http://www.cnblogs.com/default.aspx页面处理,default.aspx页面在URL中获得参数:BlogName = thinhunan。)
Dottext博客程序用IHttpHandler myhandler= PageParser.GetCompiledPageInstance (url,pagepath,context)来进行地址转义,这个方法返回的IHttpHandler的属性IsReusable有时会等于True,就是说返回的Handler会被Cache,我们在做Dottext的扩展时(如二级域名),这个机制不会出现什么问题,这是因为其实Dottext中很多种的URL都是最终给一个页面来处理,那就是能动态加载Control完成各种变化的Default.aspx页面,但如果有以下情况,问题就出来了:
1、http://thinhunan.sjjjyz.com/blog 和 http://www.sjjyz.com/blog 要由不同的aspx文件,也就是不同的类来处理时
2、http://thinhunan.sjjyz.com/blog/2005/10/27/234.html 和 http://thinhunan.sjjyz.com/blog/2005/10/27/234.html?comment=1 要由不同的类来处理时
3、同是http://thinhunan.sjjjyz.com/blog ,但要根据客户端是IE还是手机由不同的类处理时
问题就出来了,因为Caching在缓存IHttpHandler时,Key根据的是Request的Path(或者FilePath)信息,就是说,不管是上面的第一种还是第二种情况,IHttpHandler会错误的看成是可以重用缓存中的前一次有细微不同的URL生成的IHttpHandler,而第三种情况,在我们的IHttpHandlerFactory类中,判断客户端的动作也不会执行,因为HttpModules会在HttpHandlers之前进行动作,而在Machine.config文件中
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
Cache是第一个HttpModule,所以,如果第一次是用户用手机访问了你的首页,那以后用IE来访问的IE都会被送上一堆不能解析的WML代码。
由此可见,PageParser.GetCompilePageInstance()方法也许并不能满足我们的需求。那怎么办呢?
对System.Web.UI进行改进和扩展?这是行不通的,因为其中大部分类、方法都是internal的,不同Assembly不能访问。
可行的办法是:其实System.Web.UI.Page本身继承了IHttpHandler,而且它本身的IsReusable返回的是false,既然如此,那我们干脆只接用反射返回页面实例就行了,实现代码如下:
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://thinhunan.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
-----------------------------------------
原创文章,转载请注明出处