如何通过 Web.Config 即时更改 Asp.net 主题

发布于 2024-09-25 08:23:01 字数 1456 浏览 9 评论 0原文

摘要

我有一个具有超过 5 个主题的网络应用程序。每个主题针对不同的客户涵盖完全不同的风格。每当我们发布应用程序的新版本时,我们都会将其发送给所有客户。

问题。

我们在 web.config 文件的 标记中指定主题。 与这种方法一样

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

,我们可以轻松地相互更改应用程序的样式,而无需编写需要为每个应用程序进行新发布的代码。

更改 theme="Theme1"。没有任何变化,我们也没有在 application 中编写代码,那么为什么更改 theme 不会更改主题,而我们需要新的发布呢?

我们想在 web.config 或其他地方更改它,并且通过更改它来更改主题,而不需要为每个主题进行新的发布。


更新:

我发布一次,然后为每个客户复制发布的版本(5 次),然后在每个 web.config 文件中更改 theme="CustomerTheme"。但只有在发布过程中处于活动状态的主题在所有 5 个版本中可用,其他 4 个主题不可用

--

实际上主要问题是,为什么 Web.Config 中的更改需要不同的发布,而它是 XML 而不是需要遵守。我应该添加此注释,App_Theme 包含所有 5 个主题,以便所有主题都可以编译并准备使用

-

这是我发布应用程序的方式

Publish

照片链接


更新 2

此处 我发现了其他人报告的确切问题。他解决了问题,但我无法理解他是如何解决这个问题的。谁能告诉我他是如何解决这个问题的?

他使用了aspnet_compiler命令并告诉自动在页面指令上添加“主题”

(第一篇文章是问题,最后一篇文章是答案)

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无言温柔 2024-10-02 08:23:01

如果我理解正确的话,你们为每个客户都有一个主题,并且不会改变吗?

不过,我还是不明白你的发布场景?如果每个客户都有自己的 Web 应用程序,为什么要更改主题?

不过,您可以检查代码隐藏中的请求 url 并以编程方式设置主题名称吗?

伪代码:(您需要在每个请求上执行这段代码。您可以为此编写一个 HTTPHandler,或者使用 global.asax 中的 BeginRequest 事件。您还需要找到哪个属性提供必要的 URL 信息)

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

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;
}
最单纯的乌龟 2024-10-02 08:23:01

您是否将应用程序发布为预编译的?如果是这样,这可能就是原因。

为什么不将要使用的主题存储在数据库表中并在那里访问它而不是 web.config?这应该是真正的“即时”。

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'.

肤浅与狂妄 2024-10-02 08:23:01

尽管这是一篇非常旧的帖子,但我认为接受的答案并不是最好的答案。在此链接上,https://bytes.com/topic/ asp-net/answers/495850-themes-web-config 是一个正确的答案,但不够清晰。

他提到编译器正在将主题添加到每个页面,因此服务器上的 web.config 文件无法更改它。但他没有说如何避免这种情况,而且很简单。您只需在编译网站之前从 web.config 中删除 theme='Theme1' 即可。如果不存在,那么编译器不会为每个页面设置主题,您可以使用相同的代码在您喜欢的每个服务器上通过 web.config 更改主题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文