Here’s a little idea i just thought out. Using a XML-file as configuration for your application, is not a new thing. But i figured out a nice little idea. What if you want a specific configuration for different user, determined by the users permissions or group membership. A example scenario :
Your application has a lot of users, divided into groups of permissions, lets say administrators, editors and guests. Now you want a specific and a dynamically configuration file. For instance administrators have 2 more pages than the editors.
..
<pageconfiguration >
<page name=”users.aspx” >
<page name=”myaccount.aspx”>
<page name=”comments.aspx”>
</pageconfiguration>
This is a sample configuration file. Lets say you have a pageconfiguration loader, that reads every page-xmlnode. A simple solution too determine if an editor can see users.aspx or not. A not so smart developer wouldt write a bunch of if-else-statements. But what if a customer wants to add a new page to their configuration. The developer has to add another if-else-statement for that page, rebuild application and need to make a new release of the application for that single customer request.
Heres my trick
Loads your pages, via XPath and XML query. Heres my modifed configuration file.
..
<pageconfiguration >
<page name=”users.aspx” usergroups=”adm”>
<page name=”myaccount.aspx” usergroups=”*”>
<page name=”review_comments.aspx” usergroups=”adm,edi”>
</pageconfiguration>
Lets say we call the administrator groups are called adm and the editors are called edi. Administrators pagesĀ can be loaded like this :
XmlDoc.SelectNodes(“/pageconfiguration/page[@ contains(usergroups,"adm") or contains(usergroups,"*")]“);
this will get you all the pages where usergroup contains “adm” and “*”.
Simple, easy and (do i dare) smart.
Tags: asp.net, configuration, dynamic, loader, permissions, query, user, XML, XPATH, XQuery