开发者

Multiple configurations for asp.net user control

开发者 https://www.devze.com 2022-12-10 05:13 出处:网络
I\'m working on a site that can be displayed to the user in several different ways, kind of like themes, but more functionality related. So basically, the page you are viewing is in a certain state (b

I'm working on a site that can be displayed to the user in several different ways, kind of like themes, but more functionality related. So basically, the page you are viewing is in a certain state (based on the user, country etc).

The rendering of the controls on a page will vary a bit depending on the current state, and I want this to be easily configurable. (For state A, hide this field in this control, for state B show this icon etc).

In a standard web site, a control would just access a section in web.config to get the its current configuration, but now I want the control to get different configurations depending on the state the page is in.

A开发者_Python百科ny suggestions on how to implement this?


Why not just save the relevant UserControl Properties values in a database for each state. This way states can be added or modified on the fly later.


I choose to create an interface for getting configuration settings that directly mapped to ConfigurationManager.GetSection(string sectionPath). I then injected (using Spring.Net) a class that used the built in configuration manager, but tried to resolve the section path at different levels depending on the current state.

So it started by trying to get the configuration from "[CurrentState]/Application/MyControlConfiguration", if not found tried the default "Application/MyControlConfiguration". Worked pretty well...

The controls didn't have to be aware that the application can override configuration settings depending on state.

0

精彩评论

暂无评论...
验证码 换一张
取 消