Nasser Hadjloo
Nasser Hadjloo

Reputation: 12610

How to change Asp.net Theme via Web.Config on the fly

Summary

I have a web-application with more than 5 themes. Each themes covers a completely different style for different customers. whenever we publish a new version of our application we send it for all of customers.

The problem.

We specify theme in web.config file in <Page> tag. like

<page theme="Theme1" /> // or Theme2 for second customer.

with this approach we easily change the style of application from each other without writing codes which needs a new publish for each one.

With changing the theme="Theme1". nothing change and we didn't write a code in application , so why changing theme don't change the theme and we need a new publish?

we want to change it in web.config or somewhere else and with changing it the theme change without needing a new publish for each one.


Update :

I Publish Once and then copy the published version for each customer (5 times) then in each web.config file I change the theme="CustomerTheme". but only the theme which was active in publish process is usable in all of 5 versions and other 4 themes are un-usable

--

Actually the main question is that why changes in Web.Config need a different publish while it is XML and do not need a complie. I should Add this note that, App_Theme include all of 5 themes so that all of them Compiles and are ready to use

--

This is the way I publish the application

Publish

Photo Link


Update 2

here IFound the exact problem reported by someone else. he resolve the problem but I can't underestand how he resolved this Issue. can anybody tell me how he resolved the issue?

he used aspnet_compiler command and told that automatically ADDS the 'theme' on the Page directive

(first post is the question and the last post is the answer)

http://bytes.com/topic/asp-net/answers/495850-themes-web-config

Upvotes: 2

Views: 6760

Answers (3)

Filip Krystl
Filip Krystl

Reputation: 11

Even though this is a really old post, I don't think the accepted answer is the best one. On this link, https://bytes.com/topic/asp-net/answers/495850-themes-web-config is a correct answer, but not as clear as it should.

He mentioned that the compiler is adding the theme to every page, so then it can't be changed by web.config file on the server. But he didn't say what to do to avoid this and it is pretty simple. You just have to remove the theme='Theme1' from web.config before compiling the web site. If it is not there, then the compiler would not set the theme to every page and you can change the theme just by web.config on every server you like with the same exact code.

Upvotes: 1

citronas
citronas

Reputation: 19365

If I understood you correctly, you have one theme for each customer and that will not change?

Still, I do not understand your publishing scenario? Why do you want to change the Theme if each customer has its own web application?

Nevertheless, how about you check the request url in the codebehind and set the Theme Name programatically?

Pseudo-code: (you need to have this piece of code executed on every request. You could write an HTTPHandler for this, or use the BeginRequest Event in the global.asax. You also need to find which property provides the necessary URL information)

switch(Request.URL)
{
 case "www.customer1.com":
    Theme = "Customer1";
    break;
 case "www.customer2.com":
    Theme = "Customer2":
    break;
}

Upvotes: 3

JamWheel
JamWheel

Reputation: 300

Did you publish the app as precompiled? If so this could be the cause.

Why not store the theme to use in a database table and access it there rather than the web.config? This should then be truly 'on the fly'.

Upvotes: 2

Related Questions