Membership.ApplicationName = "yourfbaApplicationame"; MembershipUser user = Membership.CreateUser("admin,"password"," emaiol@g.com ");
and make sure you have the following entries in the configuration file.
<connectionStrings> <add connectionString="server=sqd01-1-cll;database=FBA;Integrated Security=SSPI;" name="FBASqlConnString" providerName="System.Data.SqlClient"/>
If you still want to use the full code and should not use the configuration file. Use below
SqlMembershipProvider ObjSqlMembershipProvider = new SqlMembershipProvider(); SqlRoleProvider ObjSqlRoleProvider = new SqlRoleProvider(); NameValueCollection ObjNameValueCollRole = new NameValueCollection(); NameValueCollection ObjNameValueCollMembership = new NameValueCollection(); MembershipCreateStatus enMembershipCreateStatus; ObjNameValueCollMembership.Add("connectionStringName", "Connection String Name"); ObjNameValueCollMembership.Add("applicationName", "ApplicatioNAme"); //these items are assumed to be Default and dont care..Should be given a look later stage. ObjNameValueCollMembership.Add("enablePasswordRetrieval", "false"); ObjNameValueCollMembership.Add("enablePasswordReset", "false"); ObjNameValueCollMembership.Add("requiresQuestionAndAnswer", "false"); ObjNameValueCollMembership.Add("requiresUniqueEmail", "false"); ObjNameValueCollMembership.Add("passwordFormat", "Hashed"); ObjNameValueCollMembership.Add("maxInvalidPasswordAttempts", "5"); ObjNameValueCollMembership.Add("minRequiredPasswordLength", "1"); ObjNameValueCollMembership.Add("minRequiredNonalphanumericCharacters", "0"); ObjNameValueCollMembership.Add("passwordAttemptWindow", "10"); ObjNameValueCollMembership.Add("passwordStrengthRegularExpression", ""); //hard coded the Provider Name,This function just need one that is present. I tried other names and it throws error. I found this using Reflector ..all the rest are take care by the above //name value pairs ObjSqlMembershipProvider.Initialize("AspNetSqlMembershipProvider", ObjNameValueCollMembership);MembershipUser user = ObjSqlMembershipProvider.CreateUser("admin,"password"," emaiol@g.com ");
This is necessary so that the connection string in the configuration file is no good. If you want this to be from code too, you need to inherit the class
Kusek
source share