(地址转义:指像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;
}
-----------------------------------------
原创文章,转载请注明出处












