BlogEngine.NET Architecture and source Code Analysis Series part12: page Common base class

Source: Internet
Author: User
Tags httpcontext inheritance blogengine

Blogbasepage

On an article I showed you the principle of blogengine.net theme and some development norms, there are a lot of content and this article has links, suggest that the two articles together to see, this effect will be better. In this article I would like to explain some of the blogbasepage,postviewbase,commentviewbase of the three classes of the internal implementation of some of the skills and how they and the page, articles and comments are organized together, hoping to read this part of the code is helpful.

Meet them.

Blogbasepage,postviewbase,commentviewbase They are the base classes of some elements, first defining them as base classes, and then using inheritance to implement I think there are mainly the following benefits:

1. Code reuse can be promoted, and for a number of similar operations, the subclass may be placed in the base class, which can be inherited directly.

2. Clear responsibilities, such as Commentview.ascx directly inherit commentviewbase in theme, Commentview.ascx just to deal with the problem of how comment will be presented.

3. Normalization, which is an important benefit of inheritance, because subclasses are a parent class, as long as it is available.

Every page under the root of the Blogbasepage:web site inherits from it, Blogbasepage inherits from page. The page is not inherited directly from page.

Postviewbase: is the base class for a post display feature section, where the postview.ascx of each topic in themes is inherited directly from it, Postviewbase inherits from UserControl.

Commentviewbase: is a comment display of the functional part of the base class, themes each topic commentview.ascx are directly inherited from it, Commentviewbase inherited from UserControl.

Implementation analysis

What the hell did blogbasepage do?

In Onpreinit, the master file (including the preview of the theme selection) is found according to the theme in blogsetting and the deletion of post is processed.

OnLoad do a lot of things, mainly in the head to add some resource references (including SIOC,APML,FOAF, etc.), in fact, when we open the page to view the source code see a number of link in the head. There are also some global variables added to the script, adding HTML for the custom head in blogsetting, adding track scripts, adding script references (implemented by Javascripthandler), Increase the style (note that the CSS compression is implemented through Csshandler).

The Onprerendercomplete is complete with the title set.

A malicious attack using comment is also handled in the onerror.

protected override void OnError (EventArgs e)
{
HttpContext ctx = HttpContext.Current;
Exception Exception = ctx. Server.GetLastError ();
if (Exception!= null && exception. Message.contains ("callback"))
{
This is a robot spam attack so we send it a 404 the status to make it go away.
CTx. Response.statuscode = 404;
CTx. Server.ClearError ();
Comment.onspamattack ();
}
Base. OnError (e);
}

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.