ASPX file substitution

We want to change / replace / replace ASPX files from time to time. This is a script.

We have a portal written with ASP.NET that already has many pages - for viewing data, updating records, reports, etc. Some clients are "really important", so we need to be able to customize specific pages only for them, so when they log in, they see a page configured for them.

The master pages are great - we can customize the header, footer, etc., but we may want to hide certain areas or completely move them. We cannot do this using master pages.

Themes / skins are good for CSS, and the controls behave differently, but again this does not allow me to completely reorganize a specific page.

So, I want to write code to go "Hey, I'm registered as a special client, go find out if there is an .aspx override page for the one I'm on. Use this. Otherwise use the .aspx that already exists . "

This means that I can have a directory on my server for each of my "special clients" with an odd .aspx file that overrides the default value.

How can i achieve this?

Thanks a lot Nick

+3
source share
2 answers

factory, .aspx. , PageHandlerFactory:

public class MyPageFactory : PageHandlerFactory
{
    public override IHttpHandler GetHandler(
        HttpContext httpContext, string requestType, string url, 
        string pathTranslated)
    {
        // Here you can inspect `HttpContext` and perform whatever checks you
        // need to determine whether or not to use your custom overridden page.
        if (shouldOverride) 
        {
            var newVirtualPath = "/Overrides/Foo/MyPage.aspx";
            string newFilePath = httpContext.Server.MapPath(newVirtualPath);

            // Now create the page instance
            IHttpHandler page = PageParser.GetCompiledPageInstance(newVirtualPath, newFilePath, httpContext);
            return page;
        }
        else 
        {
            // If we're not overriding, just return the default implementation
            return base.GetHandler(httpContext, requestType, url, pathTranslated);
        }
    }
}

web.config (IIs7):

<system.webServer>
    <httpHandlers>
        <add verb="*" path="*.aspx" type="MyPageFactory" />
    </httpHandlers>
</system.webServer>

< IIS7:

<system.web>
    <httpHandlers>
        <add verb="*" path="*.aspx" type="MyPageFactory" />
    </httpHandlers>
</sysetm.web>
+3

, ?

, , , , CMS, .. , , , XML , .

( ). , .

+1

All Articles