Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2006, 07:21 AM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to cacaldo
Default Issue with custom membership provider

I have am using the custom membership provider and I had it working fine. With the following enty in webcofig

 <membership defaultProvider="CustomizedProvider">
      <providers>
        <add name="CustomizedProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="LocalSqlServer"
             minRequiredPasswordLength="5"
             minRequiredNonalphanumericCharacters="0"
             requiresQuestionAndAnswer="false"/>
      </providers>
    </membership>

I next tried to change the passwordformat to encryptyed and replaced the above membership with the following (adding a encryption key)

 <machineKey validationKey="D61B3C89CB33A2F1422FF158AFF7320E8DB 8CB5CDA1742572A487D94018787EF42682B202B746511891C1 BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE"
                decryptionKey="FBF50941F22D6A3B229EA593F24C41203DA 6837F1122EF17" />



    <membership defaultProvider="CustomizedProvider">
      <providers>
        <add name="CustomizedProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="LocalSqlServer"
             enablePasswordRetrieval="true"
             passwordFormat="Encrypted"
             minRequiredPasswordLength="5"
             minRequiredNonalphanumericCharacters="0"
             requiresQuestionAndAnswer="false"/>
      </providers>
    </membership>

This runs fine on my localhost and I can login without any problem.

When I run this to my host server I get the following error.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The entry 'CustomizedProvider' has already been added.

Source Error:


Line 95: <membership defaultProvider="CustomizedProvider">
Line 96: <providers>
Line 97: <add name="CustomizedProvider"
Line 98: type="System.Web.Security.SqlMembershipProvider"
Line 99: connectionStringName="LocalSqlServer"

Help with this issue would be greatly appreciated.
Thanks
 
Old October 7th, 2006, 03:05 AM
Authorized User
 
Join Date: Apr 2006
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Calcado,
Sorry I can't be of an yhelp but I wonder, how's your setup? I'm trying to get the custom membership provider working but I don't understand where to find the SELECT statement in the custommembershipprovider.cs file. Could you please paste yours?

Mine looks like below (copied from support.microsoft.com). Thanks!

Pettrer

Here's the code that is in the .cs file (I'm trying out the ValidateUser method):

using System;

using System.Web;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web.Security;

using System.Collections.Specialized;

using System.Data.SqlClient;

class CustomMembershipProvider : MembershipProvider

{

public override void Initialize(string name, NameValueCollection config)

{

// Verify that config isn't null


if (config == null)

throw new ArgumentNullException("config");

// Assign the provider a default name if it doesn't have one

if (String.IsNullOrEmpty(name))

name = "AspNetCustomMembershipProvider";

// Add a default "description" attribute to config if the
// attribute doesn't exist or is empty

if (string.IsNullOrEmpty(config["description"]))

{

config.Remove("description");

config.Add("description", "Custom SQL Provider");

}

// Call the base class's Initialize method

base.Initialize(name, config);

}

public override bool ValidateUser(string username, string password)

{

SqlConnection cnn = null;

SqlCommand cmd = null;

bool userExists = true;

try

{

cnn = new SqlConnection();

cnn.ConnectionString = "myConnectionString";

cnn.Open();

string selectQry = "Select query for username and password";

cmd = new SqlCommand(selectQry, cnn);

SqlDataReader rdr = cmd.ExecuteReader();

if (!rdr.Read())

userExists = false;

}

catch (Exception ex)

{

throw ex;

}

finally

{

cmd.Dispose();

cnn.Close();

}

return userExists;

}

public override MembershipUser CreateUser(string username, string


password, string email, string passwordQuestion, string

passwordAnswer, bool isApproved, object providerUserKey,

out MembershipCreateStatus status)

{

SqlConnection cnn = null;

SqlCommand cmd = null;

MembershipUser newUser = null;

try

{

cnn = new SqlConnection();

cnn.ConnectionString = "myConnectionString";

cnn.Open();

string insertQry = "Prepare the Insert query...";

cmd = new SqlCommand(insertQry, cnn);

cmd.ExecuteNonQuery();

// Right now I am giving default values for DateTime
// in Membership constructor.

newUser = new MembershipUser(

"AspNetCustomMembershipProvider",

username, null, String.Empty, String.Empty,

String.Empty, true, false, DateTime.Now,

DateTime.Now, DateTime.Now, DateTime.Now,

DateTime.Now

);

status = MembershipCreateStatus.Success;

}

catch (Exception ex)

{

status = MembershipCreateStatus.ProviderError;

newUser = null;

throw ex;

}

finally

cmd.Dispose();

cnn.Close();

}

return newUser;

}

// MembershipProvider Properties


public override string ApplicationName

{

get { throw new NotSupportedException(); }

set { throw new NotSupportedException(); }

}

public override bool EnablePasswordRetrieval

{

get { return false; }

}

public override bool EnablePasswordReset

{

get { return false; }

}

public override int MaxInvalidPasswordAttempts

{

get { throw new NotSupportedException(); }

}

public override int MinRequiredNonAlphanumericCharacters

{

get { throw new NotSupportedException(); }

}

public override int MinRequiredPasswordLength

{

get { throw new NotSupportedException(); }

}

public override int PasswordAttemptWindow

{

get { throw new NotSupportedException(); }

}

public override MembershipPasswordFormat PasswordFormat

{

get { throw new NotSupportedException(); }

}

public override string PasswordStrengthRegularExpression

{

get { throw new NotSupportedException(); }

}

public override bool RequiresQuestionAndAnswer

{

get { return false; }

}

public override bool RequiresUniqueEmail

{

get { return false; }

}

public override MembershipUser GetUser(string username,

bool userIsOnline)

{

throw new NotSupportedException();

}

public override MembershipUserCollection GetAllUsers(int pageIndex,

int pageSize, out int totalRecords)

{

throw new NotSupportedException();

}

public override int GetNumberOfUsersOnline()

{

throw new NotSupportedException();

}

public override bool ChangePassword(string username,

string oldPassword, string newPassword)

{

throw new NotSupportedException();

}

public override bool ChangePasswordQuestionAndAnswer(string username,

string password, string newPasswordQuestion,

string newPasswordAnswer)

{

throw new NotSupportedException();

}

public override bool DeleteUser(string username,

bool deleteAllRelatedData)

{

throw new NotSupportedException();

}

public override MembershipUserCollection








FindUsersByEmail(string emailToMatch, int pageIndex,

int pageSize, out int totalRecords)

{

throw new NotSupportedException();

}

public override MembershipUserCollection




FindUsersByName(string usernameToMatch, int pageIndex,

int pageSize, out int totalRecords)

{

throw new NotSupportedException();

}

public override string GetPassword(string username, string answer)

{

throw new NotSupportedException();

}

public override MembershipUser GetUser(object providerUserKey,

bool userIsOnline)

{

throw new NotSupportedException();

}

public override string GetUserNameByEmail(string email)

{

throw new NotSupportedException();

}

public override string ResetPassword(string username,

string answer)

{

throw new NotSupportedException();

}

public override bool UnlockUser(string userName)

{

throw new NotSupportedException();

}

public override void UpdateUser(MembershipUser user)

{

throw new NotSupportedException();

}

}

...the error I get is this:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 53: finally
Line 54: {
Line 55: cmd.Dispose();
Line 56: cnn.Close();
Line 57: }






















Coding is indeed a nine-to-five job; nine pm to five am.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Membership Provider Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 August 1st, 2008 05:16 PM
Custom Membership provider question aspcoder BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 July 27th, 2008 09:59 AM
Custom Membership Provider kulkarnimonica ASP.NET 2.0 Professional 0 June 21st, 2007 03:56 PM
problem with custom membership provider hertendreef ASP.NET 2.0 Professional 8 April 17th, 2007 12:11 PM
custom membership provider msrnivas General .NET 1 September 18th, 2005 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.