Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 371705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:08:24+00:00 2026-05-12T14:08:24+00:00

We’re using ASP.Net membership providers (the SQL Server provider), and I want to be

  • 0

We’re using ASP.Net membership providers (the SQL Server provider), and I want to be able to set up an Admin user account as part of our installer. To do this, I need the ASP.Net membership provider configured so that my installer can use it – but I don’t want to have to set up a config file for the installer.

So is there a way of configuring an ASP.Net membership through code without writing a custom provider?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:08:24+00:00Added an answer on May 12, 2026 at 2:08 pm

    Ok, following the solution they conjured up here: http://forums.asp.net/p/997608/2209437.aspx

    I created a class which, in the parameterless constructor (which you need) just gets the server and port from the command line arguments. Such that I can go “MembershipInitializer.exe “SomeSqlServer\Instance” 51000.

    public class CustomSQLMembershipProvider : SqlMembershipProvider {
      private readonly string _server;
      private readonly string _port;
    
      /// <summary>
      /// Initializes a new instance of the <see cref="T:System.Web.Security.SqlMembershipProvider"/> class.
      /// </summary>
      public CustomSQLMembershipProvider() {
        string[] args = System.Environment.GetCommandLineArgs();
        // args[0] is the exe name
        _server = args[1];
        _port = args[2];
      }
    
      public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
      {
        base.Initialize(name, config);
    
        // Update the private connection string field in the base class.
        string connectionString = string.Format(@"Data Source={0},{1};Initial Catalog=aspnetdb;UID=NICCAMembership;PWD=_Password1;Application Name=NICCA;Connect Timeout=120;", _server, _port);
    
        // Set private property of Membership provider.
        FieldInfo connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
        connectionStringField.SetValue(this, connectionString);
      }
    }
    

    In the app.config of your console app (or windows app)

    <configuration>
     <connectionStrings>
      <clear/>
      <add name="MembershipDB"
        connectionString="Some Bogus String here that gets overrided in the custom class" 
        providerName="System.Data.SqlClient"/>
     </connectionStrings>
     <system.web>
      <authentication mode="Forms"/>
      <authorization>
       <deny users="?"/>
      </authorization>
      <membership>
       <providers>
        <remove name="AspNetSqlMembershipProvider"/>
        <add name="AspNetSqlMembershipProvider" 
          connectionStringName="MembershipDB" 
          applicationName="NICCA" 
          type="MyInitializeMembershipDB.CustomSQLMembershipProvider, MyInitializeMembershipDB" 
          requiresUniqueEmail="false" 
          requiresQuestionAndAnswer="false"/>
       </providers>
      </membership>
     </system.web>
    </configuration>
    

    If you are in need of the role provider bit as well, you probably have to override SqlRoleProvider in much the same way.

    If you are creating a program to automatically initialize your membership database to a specific state based but the sql server address and port name aren’t known until someone enters them into a install wizard, this will do the trick..

    Does this help?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.