Click here to Skip to main content
15,896,207 members
Articles / Web Development / ASP.NET

Introducing ASP.NET Page Modules

Rate me:
Please Sign up or sign in to vote.
3.81/5 (10 votes)
15 Apr 2010CPOL3 min read 57.5K   360   48  
This article introduces the concept of Page Modules, which are similar to HTTP Modules but related to Page Life Cycle, and the need for them.
using System;
using System.Configuration;
using System.Reflection;
using PauloMorgado.Web.UI;

namespace PauloMorgado.Web.Configuration
{
    internal class PageModuleEntry
    {
        private string name;
        private Type type;

        internal PageModuleEntry(string name, string typeName, string propertyName, ConfigurationElement configurationElement)
        {
            this.name = name ?? string.Empty;
            this.type = TypeUtils.GetType(typeName, propertyName, configurationElement);
            if (!typeof(IPageModule).IsAssignableFrom(this.type))
            {
                if (configurationElement == null)
                {
                    throw new ConfigurationErrorsException(string.Format(Properties.Resources.TypeNotModule, typeName));
                }
                throw new ConfigurationErrorsException(string.Format(Properties.Resources.TypeNotModule, typeName), configurationElement.ElementInformation.Properties["type"].Source, configurationElement.ElementInformation.Properties["type"].LineNumber);
            }
        }

        internal IPageModule Create()
        {
            return (IPageModule)Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null);
        }

        internal string ModuleName
        {
            get
            {
                return this.name;
            }
        }
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paulo Morgado
Portugal Portugal

Comments and Discussions