2

I used this video tutorial to get started and created a custom membership provider: http://channel9.msdn.com/Blogs/BomBom/Building-your-own-MemberShipProvider-in-ASPNET-20-and-use-it-in-SharePoint

I'm having trouble getting VS to debug.

I've done the following:

  • Created c# library project for .NET 3.0 and inherited MembershipProvider
  • Set signing in project settings
  • Built dll in debug
  • Put dll in the web app bin folder
  • Used sn -Tp and put public key in web app web.config
  • Added my provider to web.config

    <membership defaultProvider="AndyProvider">
      <providers>
        <clear />
        <add name="AndyProvider" 
           type="CustomMembershipProvider.AndyMembershipProvider, CustomMembershipProvider, 
           Version=1.0.0.0, Culture=neutral, PublicKeyToken=ee9911c9483b5f81" 
        />
      </providers>
    </membership>
    
  • Set Single Sign On and provider name in central administration

enter image description here

  • Attached VS 2013 to w3wp.exe processes

But when I access the site I get An unexpected error has occurred.. I'm expecting visual studio to catch an exception. It appears I'm attached correctly.

enter image description here

I don't see any errors in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS

Here's the membership provider code (all unimplemted except test code in ValidateUser)


using System;
using System.Collections.Generic;
using System.Text;

using System.Web;
using System.Web.Security;
using System.Configuration;

namespace CustomMembershipProvider
{
    public class AndyMembershipProvider : MembershipProvider
    {
        string strName = null;
        public override string Name
        {
            get
            {
                return strName;
            }
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            throw new NotImplementedException();
        }

        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
        {
            throw new NotImplementedException();
        }

        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            throw new NotImplementedException();
        }

        public override bool EnablePasswordReset
        {
            get { throw new NotImplementedException(); }
        }

        public override bool EnablePasswordRetrieval
        {
            get { throw new NotImplementedException(); }
        }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }

        public override int GetNumberOfUsersOnline()
        {
            throw new NotImplementedException();
        }

        public override string GetPassword(string username, string answer)
        {
            throw new NotImplementedException();
        }

        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            throw new NotImplementedException();
        }

        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            throw new NotImplementedException();
        }

        public override string GetUserNameByEmail(string email)
        {
            throw new NotImplementedException();
        }

        public override int MaxInvalidPasswordAttempts
        {
            get { throw new NotImplementedException(); }
        }

        public override int MinRequiredNonAlphanumericCharacters
        {
            get { throw new NotImplementedException(); }
        }

        public override int MinRequiredPasswordLength
        {
            get { throw new NotImplementedException(); }
        }

        public override int PasswordAttemptWindow
        {
            get { throw new NotImplementedException(); }
        }

        public override MembershipPasswordFormat PasswordFormat
        {
            get { throw new NotImplementedException(); }
        }

        public override string PasswordStrengthRegularExpression
        {
            get { throw new NotImplementedException(); }
        }

        public override bool RequiresQuestionAndAnswer
        {
            get { throw new NotImplementedException(); }
        }

        public override bool RequiresUniqueEmail
        {
            get { throw new NotImplementedException(); }
        }

        public override string ResetPassword(string username, string answer)
        {
            throw new NotImplementedException();
        }

        public override bool UnlockUser(string userName)
        {
            throw new NotImplementedException();
        }

        public override void UpdateUser(MembershipUser user)
        {
            throw new NotImplementedException();
        }

        public override bool ValidateUser(string username, string password)
        {
            return true;
            //throw new NotImplementedException();
        }
    }
}

1 Answer 1

0

I upped the log level to verbose and saw this:

Application error when access /, Error=Provider name cannot be null or empty.   
  at System.Configuration.Provider.ProviderCollection.Add(ProviderBase provider)     
  at System.Web.Security.MembershipProviderCollection.Add(ProviderBase provider)     
  at System.Web.Configuration.ProvidersHelper.InstantiateProviders(ProviderSettingsCollection configProviders, ProviderCollection providers, Type providerType)     
  at System.Web.Security.Membership.Initialize()     
  at System.Web.Security.Membership.get_Provider()     
  at Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler.OverrideExecuteUrlPath()     
  at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)     
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExe...  

So I added this and the error went away:


namespace CustomSharePointProvider
{
    public class AndyMembershipProvider : MembershipProvider
    {
        public override string Name
        {
            get
            {
                return "AndyMembership";
            }
        }

Your Answer

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

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