惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Vercel News
Vercel News
博客园_首页
Y
Y Combinator Blog
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
博客园 - Franky
Engineering at Meta
Engineering at Meta
量子位
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium

博客园 - 天雪

交换机的重要技术参数 JavaScript:prototype属性使用说明 编译器错误信息: CS0016 JavaScript应用:Iframe自适应其加载的内容高度 Web开发实用浏览器(工具)插件 什么是VML 经典足球 flash+xml结合应用实例下载 一个10岁小孩 网页屏蔽(左右键,代码等)的非JS方法 Asp.net Xml开发网络硬盘 CSS expression VS Script event 图解DOM中关于对象范围的属性。 MapBar中坐标的加密和解密(JS实现) Google Earth经典坐标 通过DOM操作数据(下) 通过DOM操作数据(上) DOM 精简知识教程 鼠标拖动层的JS方法
Asp.net地址转义(分析)加强版--Dottext的地址分析模块的不...
天雪 · 2006-06-24 · via 博客园 - 天雪

Posted on 2006-06-24 11:11  天雪  阅读(257)  评论()    收藏  举报

(地址转义:指像http://thinhunan.cnblogs.com/这样的地址,被转义成http://www.cnblogs.com/default.aspx页面处理,default.aspx页面在URL中获得参数:BlogName = thinhunan。)

        <httpModules>
            
<add
                
name="OutputCache"
                type
="System.Web.Caching.OutputCacheModule" />
……        
</httpModules>

Cache是第一个HttpModule,所以,如果第一次是用户用手机访问了你的首页,那以后用IE来访问的IE都会被送上一堆不能解析的WML代码。

由此可见,PageParser.GetCompilePageInstance()方法也许并不能满足我们的需求。那怎么办呢?
对System.Web.UI进行改进和扩展?这是行不通的,因为其中大部分类、方法都是internal的,不同Assembly不能访问。

可行的办法是:其实System.Web.UI.Page本身继承了IHttpHandler,而且它本身的IsReusable返回的是false,既然如此,那我们干脆只接用反射返回页面实例就行了,实现代码如下:

        private static Assembly _dotTextWebAssembly = null;
        
/// <summary>
        
/// Assembly
        
/// </summary>

        private static Assembly DotTextWebAssembly
        
{
            
get
            
{
                
if(_dotTextWebAssembly == null)
                
{
                    _dotTextWebAssembly 
= (Assembly)HttpRuntime.Cache["WebDllPath"];
                    
if(_dotTextWebAssembly == null)
                    
{
                        AssemblyName an 
= new AssemblyName();
                        an.Name 
= "Dottext.Web";
                        _dotTextWebAssembly 
= AppDomain.CurrentDomain.Load(an);
                        HttpRuntime.Cache.Insert(
"WebDllPath",_dotTextWebAssembly,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromDays(1),System.Web.Caching.CacheItemPriority.NotRemovable,null);
    
                    }

                }

                
                
return _dotTextWebAssembly;
            }

        }

        
private static IHttpHandler GetWapHandlerByPage(string pageName)
        
{
            IHttpHandler waphandler 
= null;
            
//waphandler = (IHttpHandler)HttpRuntime.Cache["WapHandler_"+pageName]; 此处不能用Cache,因为Handler的IsReUsable为false;
            
//if(waphandler == null)
            
//{
                Type type = DotTextWebAssembly.GetType("Dottext.Web."+pageName.Replace(".aspx",""),true,true);
                waphandler 
= (IHttpHandler)System.Activator.CreateInstance(type);
                
//HttpRuntime.Cache.Insert("WapHandler_"+pageName,waphandler,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromHours(1),System.Web.Caching.CacheItemPriority.NotRemovable,null);
            
//}
            return waphandler;
        }


-----------------------------------------
原创文章,转载请注明出处