Programmatic Configuration

Topics: General discussion, Security Application Block
Apr 22, 2007 at 6:46 PM
Can someone explain me how to do it? I tried to find info on Internet but only references I found was with Enterprise Library Configuration. Also tried searching true source code and various classes but with no success.

I need a way to programmaticaly add new rules to AuthorizationRuleProvider ( default ).

Any help??
Apr 23, 2007 at 6:40 PM
A good place to start is probably the Web Client Software Factory. It has an AuthorizationRulesService Class that implements GetAuthorizationRules and RegisterAuthorizationRule to help programmatically provide user and role based security in a composite web application. Even if you want the functionality for a smart client application, I am sure it will still apply.

There is also the Smart Client Software Factory that may have something similar: Smart Client Software Factory.




David Hayden
Microsoft MVP C#
Apr 24, 2007 at 2:26 AM
Thx Dave, I'll try it now.
Apr 24, 2007 at 2:58 AM
Ohhh, is there some easier way than to download all that stuff???
I have limited download which is now < 100MB
I tried many thing but closest thing to change rules programaticaly was a

which has property AuthorizationProviders but the count for it is empty ???!!??!?

And with
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource f =
new Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource("entlib.config");

I got this error.
By the way i have EntLib 3.0
An error occurred creating the configuration section handler for securityConfiguration: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\NetTiers\DLearn\DLearn.Website\entlib.config line 3)

P.S.Ill download those files tommorow and than ill post again when i try .
Apr 24, 2007 at 3:04 AM
Edited Apr 24, 2007 at 3:05 AM
I think i found the a error 1sec after I posted the last message
I said
"By the way i have EntLib 3.0"
but 2 lines down writes
" **y, Version=, Cu* i think this is the problem. "
It seems that the nettiers Security block is based on 2.0 Ent. lib. but i have only dll files.
Ill inform you when i configure the app to use security block from Ent Lib 3.0

Apr 24, 2007 at 3:40 AM
Edited Apr 24, 2007 at 9:52 AM
I made a new asp .net web site project in VS 2005 and added Security Block
through Ent. Lib. Conf. Editor
At last i succeded to get Rules from SystemConfigurationSource class by getting
section "securityConfiguration" and from there provider and from provider rules.

When i added
/*AuthorizationRuleProviderData d = ....*/

i got error "The configuration is read only."

if i copy the securityConfiguration to another SecuritySettings via
XmlReader/Writer i got this error when adding new rule:

The element 'add' has been locked in a higher level configuration.

Rules section is not locked as its parents.
Any workaround???
Sep 6, 2007 at 10:31 PM
I have the same issue. you ever figure how to do this???

Sep 6, 2007 at 11:46 PM
Hi Tom,

Configuration for a .NET application is read only. Why do you need to modify it?

Sep 7, 2007 at 2:43 AM
hi fernando,

I need to add AuthorizationRuleData dynamically from a database and not hard coded into the web.config where it is only accessable to the web application.

something like this:
but is only the rule and don't know how to add it?
IAuthorizationRule ruleData = new AuthorizationRuleData("TestRule","I:TestUser");

instead of like this:
<add expression="R:Administrator" name="AllowAdministerPermissions"/>
<add expression="R:Administrator OR R:Operator" name="AllowCreateTransfer"/>
<add expression="R:Administrator" name="AllowViewAccountsSummary"/>
<add expression="R:Administrator" name="AllowViewPaymentHistory"/>

I also should be able to do this without having to create an entire custom Authorization Provider. I can dynamically add rule elements, (url, rule name) why can't i also be able to add rule data, (rule name, expression)?