Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 952 karma points
    Feb 08, 2010 @ 00:53
    Tom
    0

    Make all pages inherit from a custom class?

    Hi All,

    just wondering if there was a way to get all pages for my umbraco solution to inherit from a base class i want to write..

     

    i have a scenario where i want the same behaviour for every page in the system.. ie

     

     

    public

     

    abstract class MyCustomPage :

    Page or UmbracoPage or whatever the base page type is

    {

    cheers,

    Tom

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 08, 2010 @ 00:58
    Lee Kelleher
    0

    Hi Tom,

    (I think some of your original post got cut-off?)

    Are you referring to your front-end ASPX pages?  If so, then you can do the following:

    Create your new base page class, inheriting from "umbraco.UmbracoDefault".  Then edit the "/default.aspx", and change the "Inherits" reference:

    <%@ Page language="c#" AutoEventWireup="True" Inherits="MyCustomPage" trace="true" validateRequest="false" %>

    Hope that helps?

    Good luck, Lee.

  • Tom 713 posts 952 karma points
    Feb 08, 2010 @ 01:00
    Tom
    0

    If i have a master document type does that create a class i can extend?

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 08, 2010 @ 01:09
    Lee Kelleher
    0

    Master document-type? or MasterPage (template)?

    Doc-type - no, they don't have a class - they are Umbraco-specific; completely outside of the ASP.NET framework.

    MasterPages can have code-behind (or even inline-code) classes that you can extend/inherit.  It all comes down to what you want to do?

    What is the behaviour that you want on every page? (your code-snippet got cut-off in your original post).

    Thanks, Lee.

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Feb 08, 2010 @ 03:06
    Aaron Powell
    1

    As Lee has pointed out the best way is to set a class for the master page to inherit from, this will give you (some) access to code behind on ever request processed.

    All requests will have the events/ properties/ members of System.Web.UI.MasterPage run through your class on each request, but keep in mind that this is different to having System.Web.UI.Page as the base.

    There's no way without a huge amount of work to route through your own class which inherits from Page, essentially that requires rewriting the Umbraco request pipeline, something that you don't want to enter into lightly.

    Maybe if you explain what you're trying to achieve we can give more options to you, as a HttpModule may be a valid idea.

  • Tom 713 posts 952 karma points
    Feb 08, 2010 @ 10:28
    Tom
    0

    Thanks guys.. i got around it by writing a module instead but still was interesting to know!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies