.net 4.5 Web.Security.Membership.Providers remove throws system.notsupported exception. Why? -


in order better understanding of how wire in auth functionality in .net mvc4 application, thought i'd take apart website 'internet application' template produces. i'm looking how implement claims aware (such this: https://github.com/brockallen/brockallen.membershipreboot)

as part of i've found myself looking @ method webmatrix.webdata.websecurity.preappstartinit() contains following code:

 const string builtinmembershipprovidername = "aspnetsqlmembershipprovider";     var builtinmembership = membership.providers[builtinmembershipprovidername];     if (builtinmembership != null)     {         var simplemembership = createdefaultsimplemembershipprovider(builtinmembershipprovidername, currentdefault: builtinmembership);         membership.providers.remove(builtinmembershipprovidername);         membership.providers.add(simplemembership);     } 

if try run similar in console app throws system.notsupportedexception @ point membership.providers.remove(builtinmembershipprovidername); called. expected if collection has had setreadonly method called, hasn't. i'm not sure why happening in console app code, not web application. have ideas?

this confused me while too. trick timing of initialisation. needs performed @ stage. while digging around webmatrix.webdata namespace, there couple of other pieces @ see how works.

there preapplicationstartmethod assembly attribute applied:

[assembly: preapplicationstartmethod(typeof(preapplicationstartcode), "start")]

the method specified in attribute called part of application start-up sequence. preapplicationstartcode.start() method call websecurity.preappstartinit() performing other configuration tasks.

you can replicate functionality doing same thing. add preapplicationstartmethod attribute assembly , have call 'start-up' method of own. @ stage, able play around membership providers collection.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -