asp.netthemesdefaultapp-globalresources

Default ASP.NET Themes


Is it possible to create a default theme for an ASP.NET Website?

For example, If I had a theme called "Default", and ive selected a theme called "NewTheme" and I referenced a file which doesn't exist in the "NewTheme" but does exist in the "Default" theme like:

<asp:image id="img" runat="server" ImageUrl="~/Images/image.jpg" />

Could that then be taken from "/App_Themes/Default/Images/image.jpg" if it does not exist at "/App_Themes/NewTheme/Images/image.jpg"?

Furthermore if a CSS class didn't exist in "NewTheme", but it did in "Default", then could it take the "Default"? In fact, I think it would be better if it first took all the default styles, and then overrides any that "NewTheme" have which clashes.

I know Global References work similar to this because if ive selected "es" localization, and a key doesn't exist in the webreference.resx.es file but it does in webreference.resx, then itll take the value from there.

I think this would be important functionality for ASP.NET Themes as I can imagine different themes only having certain images changed, and certain styles changed. I can't imagine every image and every style always being totally different for each Theme. And therefore without this functionality, its going to be a case of duplicating styles/images, which I'm not a fan of (for obvious reasons!).


Solution

  • This functionality isn't built into ASP.NET. Nevertheless, you could implement it fairly easily:

    1. Hook the HttpApplication.BeginRequest event in Global.asax or in a custom HTTP module.
    2. Look for requests with URLs under "/App_Themes/NewTheme/".
    3. Check whether the file at HttpRequest.PhysicalPath exists.
    4. If the file doesn't exist, call HttpContext.RewritePath and replace "NewTheme" in the request URL with "Default".