In order to get a better understanding of how to wire in auth functionality in .net MVC4 application, I thought I'd take apart the website that the 'Internet Application' template produces. Ultimately I'm looking into how I would implement something that is claims aware (such as this: https://github.com/brockallen/BrockAllen.MembershipReboot)
As part of this I've found myself looking at the method WebMatrix.WebData.WebSecurity.PreAppStartInit() which contains the 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 I try to run something similar in a console app it throws a System.NotSupportedException at the point Membership.Providers.Remove(BuiltInMembershipProviderName);
is called. This is to be expected if the collection has had its SetReadOnly
method called, but it hasn't. I'm not sure why this is happening in the console app code, but not the Web Application. Anyone have any ideas?