Limitations of the dottext address analysis module and Corresponding Solutions

Source: Internet
Author: User

(Address escape: Refers to image encoding = thinhunan .)

Dottext blog program using ihttphandler myhandler =Pageparser. getcompiledpageinstance(URL, pagepath, context) to escape the address. The ihttphandler attribute isreusable returned by this method is sometimes true, that is, the returned handler will be cached, during dottext extension (such as a second-level domain name), this mechanism will not cause any problems. This is because many types of URLs in dottext are finally processed by a page, that is, the default that can dynamically load the control to complete various changes. the ASPX page, but the problem arises if:
1. http://thinhunan.sjjjyz.com/blog and http://www.sjjyz.com/blog should be handled by different aspx files, that is, different classes
Http://thinhunan.sjjyz.com/blog/2005/10/27/234.html and http://thinhunan.sjjyz.com/blog/2005/10/27/234.html? When comment = 1 is to be processed by different classes
3, the same is http://thinhunan.sjjjyz.com/blog, but according to the client is IE or mobile phone by different classes of Processing

The problem arises, because when caching caches ihttphandler, the key is based on the Request Path (or filepath) information, that is, whether it is the first or second case, ihttphandler may mistakenly think that ihttphandler generated by a slightly different URL in the cache can be reused. In the third case, in our ihttphandlerfactory class, the client action will not be executed, because httpmodules will perform the action before httphandlers, and in the machine. config File

<Httpmodules>
<Add
Name = "outputcache"
Type = "system. Web. caching. outputcachemodule"/>
...... </Httpmodules>

Cache is the first httpmodule. Therefore, if you visit your homepage on your mobile phone for the first time, ie accessed by IE will be sent with a bunch of unresolvable WML code.

It can be seen that the pageparser. getcompilepageinstance () method may not meet our needs. What should we do?
How to improve and expand system. Web. UI? This is not feasible, because most of the classes and methods are internal, and different assemblies cannot be accessed.

The feasible method is: in fact, system. web. UI. page itself inherits ihttphandler, and its isreusable returns false. In this case, we simply use reflection to return the page instance. The implementation code is as follows:

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 ();
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 cannot be used here, because the isreusable of handler is 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;
}

-----------------------------------------
Original article, reprinted please indicate the source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.