YodasMyDad
YodasMyDad

Reputation: 9475

Change Attribute Of Membership Provider Programmatically In Web.Config

I have the following defaultmembership provider in my web.config

<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" />

I am trying to update the enablePasswordReset from false to true programmatically but am struggling.. This is as far as I got!

ConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
var section = (MembershipSection)config.GetSection("system.web/membership");

var defaultProvider = section.DefaultProvider;
var providerSettings = section.Providers[defaultProvider];

// Now what?

Now I can't figure out how to get the attribute and update it? any hints / examples greatly appreciated.

Upvotes: 3

Views: 2377

Answers (2)

YodasMyDad
YodasMyDad

Reputation: 9475

I figured it out

        var config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        var section = (MembershipSection)config.GetSection("system.web/membership");

        var defaultProvider = section.DefaultProvider;
        var providerSettings = section.Providers[defaultProvider];
        providerSettings.Parameters.Set("enablePasswordReset", "true");
        config.Save();

Upvotes: 4

Brian Mains
Brian Mains

Reputation: 50728

I would recommend creating a custom membership provider and using another source for the setting. It can be dangerous to change a setting; I assume this is a user-exposed feature to allow an admin to turn it on or off?

If you can create a custom membership provider that pulls the information from the database or XML file and then allow the feature or not. Not sure exactly where to put this code, it would depend on whether you are using the ASP.NET controls, or if you are custom using the API...

HTH.

Upvotes: 0

Related Questions