0

I'm writing my first MVC app right now and am creating a new MembershipProvider but am encountering some compile errors that are just plain wrong in the process. Here is my code:

public class ProfileProvider : MembershipProvider
{
    protected NameValueCollection Config = null;
    protected new String Name = null;
    protected String _PasswordStrengthRegularExpression = "";
    protected int _MinRequiredNonAlphanumericCharacters = 0;
    protected int _MinRequiredPasswordLength = 0;
    protected String _PasswordFormat = "";
    protected Boolean _RequiresUniqueEmail = false;
    protected int _PasswordAttemptWindow = 0;
    protected int _MaxInvalidPasswordAttempts = 0;
    protected String _ApplicationName = "";
    protected Boolean _RequiresQuestionAndAnswer = false;
    protected Boolean _EnabledPasswordReset = false;
    protected Boolean _EnablePasswordRetrieval = false;

    protected override String PasswordStrengthRegularExpression
    {
        get
        {
            return this._PasswordStrengthRegularExpression;
        }
        set
        {
            this._PasswordStrengthRegularExpression = value;
        }
    }
    public override int MinRequiredNonAlphanumericCharacters
    {
        get
        {
            return this._MinRequiredNonAlphanumericCharacters;
        }
        set
        {
            this._MinRequiredNonAlphanumericCharacters = value;
        }
    }
    public override int MinRequiredPasswordLength
    {
        get
        {
            return _MinRequiredPasswordLength;
        }
        set
        {
            this._MinRequiredPasswordLength = value;
        }
    }
    public override String PasswordFormat
    {
        get
        {
            return this._PasswordFormat;
        }
        set
        {
            this._PasswordFormat = value;
        }
    }
    public override Boolean RequiresUniqueEmail
    {
        get
        {
            return _RequiresUniqueEmail;
        }
        set
        {
            this._RequiresUniqueEmail = value;
        }
    }
    public override int PasswordAttemptWindow
    {
        get
        {
            return this._PasswordAttemptWindow;
        }
        set
        {
            this._PasswordAttemptWindow = value;
        }
    }
    public override int MaxInvalidPasswordAttempts
    {
        get
        {
            return this._MaxInvalidPasswordAttempts;
        }
        set
        {
            this._MaxInvalidPasswordAttempts = value;
        }
    }
    public override String ApplicationName
    {
        get
        {
            return this._ApplicationName;
        }
        set
        {
            this._ApplicationName = value;
        }
    }
    public override Boolean RequiresQuestionAndAnswer
    {
        get
        {
            return this._RequiresQuestionAndAnswer;
        }
        set
        {
            this._RequiresQuestionAndAnswer = value;
        }
    }
    public override Boolean EnablePasswordReset
    {
        get
        {
            return this._EnabledPasswordReset;
        }
        set
        {
            this._EnabledPasswordReset = value;
        }
    }
    public override Boolean EnablePasswordRetrieval
    {
        get
        {
            return this._EnablePasswordRetrieval;
        }
        set
        {
            this._EnablePasswordRetrieval = value;
        }
    }

And here are my compile errors:

Error   7   'EmptyMVC.Controllers.ProfileProvider.RequiresUniqueEmail.set': cannot override because 'System.Web.Security.MembershipProvider.RequiresUniqueEmail' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   78  13  EmptyMVC
Error   10  'EmptyMVC.Controllers.ProfileProvider.RequiresQuestionAndAnswer.set': cannot override because 'System.Web.Security.MembershipProvider.RequiresQuestionAndAnswer' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   122 13  EmptyMVC
Error   3   'EmptyMVC.Controllers.ProfileProvider.PasswordStrengthRegularExpression': cannot change access modifiers when overriding 'public' inherited member 'System.Web.Security.MembershipProvider.PasswordStrengthRegularExpression'   C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   28  35  EmptyMVC
Error   6   'EmptyMVC.Controllers.ProfileProvider.PasswordFormat': type must be 'System.Web.Security.MembershipPasswordFormat' to match overridden member 'System.Web.Security.MembershipProvider.PasswordFormat'   C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   61  32  EmptyMVC
Error   8   'EmptyMVC.Controllers.ProfileProvider.PasswordAttemptWindow.set': cannot override because 'System.Web.Security.MembershipProvider.PasswordAttemptWindow' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   89  13  EmptyMVC
Error   5   'EmptyMVC.Controllers.ProfileProvider.MinRequiredPasswordLength.set': cannot override because 'System.Web.Security.MembershipProvider.MinRequiredPasswordLength' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   56  13  EmptyMVC
Error   4   'EmptyMVC.Controllers.ProfileProvider.MinRequiredNonAlphanumericCharacters.set': cannot override because 'System.Web.Security.MembershipProvider.MinRequiredNonAlphanumericCharacters' does not have an overridable set accessor    C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   45  13  EmptyMVC
Error   9   'EmptyMVC.Controllers.ProfileProvider.MaxInvalidPasswordAttempts.set': cannot override because 'System.Web.Security.MembershipProvider.MaxInvalidPasswordAttempts' does not have an overridable set accessor    C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   100 13  EmptyMVC
Error   12  'EmptyMVC.Controllers.ProfileProvider.EnablePasswordRetrieval.set': cannot override because 'System.Web.Security.MembershipProvider.EnablePasswordRetrieval' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   144 13  EmptyMVC
Error   11  'EmptyMVC.Controllers.ProfileProvider.EnablePasswordReset.set': cannot override because 'System.Web.Security.MembershipProvider.EnablePasswordReset' does not have an overridable set accessor  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   133 13  EmptyMVC
Error   1   'EmptyMVC.Controllers.ProfileProvider' does not implement inherited abstract member 'System.Web.Security.MembershipProvider.PasswordStrengthRegularExpression.get'  C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   12  18  EmptyMVC
Error   2   'EmptyMVC.Controllers.ProfileProvider' does not implement inherited abstract member 'System.Web.Security.MembershipProvider.PasswordFormat.get' C:\Users\DigitalJedi\documents\visual studio 2010\Projects\EmptyMVC\EmptyMVC\Controllers\ProfileController.cs   12  18  EmptyMVC

I've taken a couple of passes at this, I've tried using the 'new' keyword instead of the override, and nothing seems to work.

Rawling
  • 49,248
  • 7
  • 89
  • 127
DigitalJedi805
  • 1,486
  • 4
  • 16
  • 41
  • 1
    Did you read each entire message? – SLaks Mar 20 '12 at 16:42
  • There are a couple that I can resolve on my own, but the ones that I can't figure out are 'cannot override because'... 'does not have an overridable set accessor'. How can I override the get method and not override the set method... – DigitalJedi805 Mar 20 '12 at 16:44
  • What did you not understand in the error messages? – Oded Mar 20 '12 at 16:44
  • @DigitalJedi805 - Don't implement a `set`. Just have a `get`. – Oded Mar 20 '12 at 16:45
  • Okay... Seems reasonable enough, but that will remove my ability to set these fields outside of this class... Which is sort of the reason for having a setter... I find it odd that any property would have one without the other. – DigitalJedi805 Mar 20 '12 at 16:46
  • @DigitalJedi805 - Read only properties are rather common. – Oded Mar 20 '12 at 16:47
  • Thanks @Oded, I don't typically write any properties as read-only, so the convention for doing so was a bit past me. Thanks. – DigitalJedi805 Mar 20 '12 at 16:51
  • It's sad to say that a community as valuable as this one has such misaligned morals. Thanks; Moderator. – DigitalJedi805 Mar 20 '12 at 17:01
  • possible duplicate of [Override Get, But Not Set](http://stackoverflow.com/questions/2026546/override-get-but-not-set) – nawfal Feb 19 '13 at 15:34

1 Answers1

1

The property that you're overriding on the abstract base class doesn't have a Setter.

From the answers to this question, it doesn't look like you can do what you want.

Community
  • 1
  • 1
NeilD
  • 2,278
  • 3
  • 24
  • 28
  • Well I'd accept your answer but sadly I'm still some sort of rookie and can't for another eight minutes. I suppose this answers it, but still seems 'obscure'. Thanks for your help. – DigitalJedi805 Mar 20 '12 at 16:49