1

I'm creating a ASP.NET MVC 4 application that uses Database First Entity Framework for database access. I have my own membership tables and I implemented my own Membership provider and Role provider. The problem is that i don't know how to use them. Is there a way to override WebSecurity class or change its methods so it uses my Membership provider? Or should I use Membership and Role provider directly without the WebSecurity facade?

1

1 Answer 1

0

The WebSecurity helper class is designed for use with the ExtendedMembershipProvider class (on which SimpleMembershipProvider amongst others are based). If you based your provider and your site is configured to use an ExtendedMembership based provider, the recommended approach is to use WebSecurity (although it exposes only a subset of what the underlying provider interface is capable of.

If your provider is based on the original .NET MembershipProvider and your site is configured accordingly, you will deal directly with the provider: typically the Membership and Role classes.

This article gives a useful overview of the relationship between the different providers and the ways they are intended to be used: http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx

2
  • Thanks, this really cleared up some things for me. So you can only use WebSecurity as is, you can't change its methods, right? This nuget.org/packages/CodeFirstMembershipProviderSharp/1.0.0 is something I used so far (only adjusted it for Database first) and it actually has a WebSecurity class implementation... I can't figure out how to get that.
    – DBWhite
    Nov 3, 2013 at 17:49
  • 1
    That's right. WebSecurity is a static class so cannot be inherited. It provides a simplified way of interacting with the Membership provider. If you want to do something more complicated, either work directly with the membership provider, or you could write your own facade along the lines of WebSecurity if it makes sense to do so. Nov 3, 2013 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.