开发者

What's the benefits of Custom Membership in .Net?

i'm building a custom membership in .net and i don't understand real benefits of them, what the benefits? Here is my class that inherits from MembershipProvider:

public class MembershipService : MembershipProvider
{
  public override bool ValidateUser(string username, string password)
  {
    Credencial credencial = context.Credencial.Where(x => x.Usuario == username).FirstOrDefault();

    if (credencial == null) return false;

    if (credencial.Senha == password)
    {
      return true;
    }

    return false;
  }
}

And that's my configuration in web.config:

<membership defaultProvider="MembershipService" userIsOnlineTimeWindow="15">
  <providers>
    <clear />
    <add
      name="MembershipService"
      type="Questiona2011.Services.MembershipService" />
  </providers>
</membership>

Here's where i use them:

[HttpPost]
public ActionResult Index(IndexViewModel indexViewModel)
{
    if (ModelState.IsValid)
    {
        if (MembershipService.ValidateUser(indexViewModel.Usuario, indexViewModel.Senha))
        {
            FormsAuthenticationService.SignIn(indexViewModel.Usuario, false);
            return RedirectToAction(开发者_JAVA技巧"Index", "Default");
        }
    }

    return View();
} 

I don't understand, this class MembershipService i don't need to inherits from MembershipProvider.

What's the real benefits using a Custom Membership that inherits from MembershipProvider?

Why I need to inherit from MembershipProvider?


If you want to know why you must inherit from the framework's base class; perhaps you might check the documentation. Specifically, it says that you must inherit the abstract class MembershipProvider which already inherits ProviderBase. Therefore, as with all abstract class, it must therefore provide some implementation for common functionality (most likely to do with configuration into the config files).

The main benefit for rolling your own is to alter the behaviour of the framework's implementations (for example, to connect to your existing database schema). Doing so enables you to make use of the Membership controls - including Login, LoginView, CreateUserWizard, ChangePassword, etc.


If you are already creating custom memebership you might be knowing why you are doing it .

If you need additional fields in your registration you will build custom one . Generally when you create a custom membership provider that uses custom SQL Server tables separate from the pre-defined tables used by the standard provider.


For a time I used it and one day woke up.. what the gain with this inheritance?

The answer is that I got in my scenarios had no gain. From this day forward I no longer use the Membership, I created a table structure and classes I found most appropriate to my reality. And I do not regret.

Overall Membership is indicated to avoid having to reinvent the wheel... the guys still argues that it is stable and has worked years. Any solution that does not bring out this same guarantee. E as the great majority come from webforms using Membership, continued using the same in the MVC.

MY opinion is that you do not win anything with this inheritance. In real it's like you would use a given interface, since it needs implement all the code! Unless using with Web Forms Controls with the Login Controls where i no need to code if I had a Membership Class, but MVC is my scenario where I have no controls.

Anyway, I have to say is this. I've never had a situation that use custom membership (with inheritance) would be better! FormsAuthentication class, RoleProvider class and my custom Authentication class do the work with authentication and authorization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜