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

  • SEARCH
  • Home
  • 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 7490357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:35:19+00:00 2026-05-29T15:35:19+00:00

This is a continuation of my last question: Internal Database – ASP.NET Auto Web

  • 0

This is a continuation of my last question: “Internal Database – ASP.NET Auto Web Site Registration on User Creation”. I am running the following code. This is just a test block of code. It works but my problem is it creates the default SQLEXPRESS ASPNETDB.MDF in the App_Data Directory. This is not what I want.

// Create a MembershipCreateStatus Status for Reporting...
MembershipCreateStatus status = new MembershipCreateStatus();
// Setup SqlMembershipProvider for Initialization...
SqlMembershipProvider sqlProvider = new SqlMembershipProvider();
// Setup a NameValueCollection...
NameValueCollection config = new NameValueCollection();
// Set the Connection Name of the SQL Connection String...
string SQLDBNameString = "My Company Database.Properties.Settings.ConnectionString";
// Update the private connection string field in the base class. 
string connectionString = "Data Source=Server;Initial Catalog=’My Company Database';User ID=USERNAME;Password=PASSWORD";
// Username of the account to add...
string username = "User121";
// Generate a dynamic Password....
string password = Membership.GeneratePassword(8, 1);
// Email Address of the User...
string email = "email@email.com";

try
{
    string Name = "My Company Database";

    config.Add("applicationName", "My Company Database");
    config.Add("maxInvalidPasswordAttempts", "5");
    config.Add("passwordAttemptWindow", "10");
    config.Add("minRequiredPasswordLength", "8");
    config.Add("passwordStrengthRegularExpression", "");
    config.Add("enablePasswordReset", "True");
    config.Add("enablePasswordRetrieval", "False");
    config.Add("requiresQuestionAndAnswer", "False");
    config.Add("requiresUniqueEmail", "True");
    config.Add("passwordFormat", "Hashed");
    config.Add("connectionStringName", SQLDBNameString);

    sqlProvider.Initialize(Name, config);

    ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[SQLDBNameString];
    if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty))
    {
        throw new Exception("Connection string cannot be blank.");
    }

    // connectionString = ConnectionStringSettings.ConnectionString;

    MembershipUser newUser = Membership.CreateUser(username, password, email, "Whats My Password", password, true, out status);
}
catch (Exception ex)
{
    String message = "Error...\r\n\r\n" + ex.ToString();
    String caption = "Error";
    MessageBoxButtons button = MessageBoxButtons.OK;
    MessageBoxIcon icon = MessageBoxIcon.Asterisk;
    MessageBox.Show(message, caption, button, icon);
}

MessageBox.Show("Account Creation   : " + status.ToString() + "\r\n" 
              + "Username is        : " + username + "\r\n" 
              + "Password is        : " + password + "\r\n" 
              + "Email              : " + email);

This code is running in a C# Application, SQL Front end database and it is supposed to automatically create a user so they can login to a web page once I have added them to my database. This Code is not running in a ASP Website Application. My “config” is not being initalised from what I can see. Any help is much appreaciated!

  • 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-29T15:35:20+00:00Added an answer on May 29, 2026 at 3:35 pm

    Finally a solution that works through out my website and C# Internal Database.

    A steep learning curve on my part. It is actually much simpler than I thought. Here is the Code that needs to go into the app.config file that needs to be in your C# Project:

    <configuration>
    <configSections>
    </configSections>
    <connectionStrings>
    <add name="My Company Database.Properties.Settings.ConnectionString"
        connectionString="Data Source=Server;Initial Catalog='My Company Database';Persist Security Info=True;User ID=MyUserName;Password=MyPassword"
        providerName="System.Data.SqlClient" />
    </connectionStrings>
    
    <system.web>
    <compilation debug="true" targetFramework="4.0" />
    
    <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    
    <membership>
    <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="My Company Database.Properties.Settings.ConnectionString"
             enablePasswordRetrieval="False" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
    </providers>
    </membership>
    
    </system.web>
    
    </configuration>
    

    Here is the Code to use the default MembershipProvider():

    // Create a MembershipCreateStatus Status for Reporting...
    MembershipCreateStatus status = new MembershipCreateStatus();
    
    // Username of the account to add...
    string username = "User121";
    // Generate a dynamic Password....
    string password = "P@55W0Rd";
    // Email Address of the User...
    string email = "email@email.com";
    // Password Question of the User...
    string passwordQuestion = "My Password Question?";
    // Password Answer of the User...
    string passwordAnswer = "My Password Answer!";
    
    try
    {
    Membership.CreateUser(username, password, email, passwordQuestion, passwordAnswer, true, out status);
    }
    catch (Exception ex)
    {
        this.richTextBox1.Text = "Error...\r\n\r\n" + ex.ToString();
    }
    
    this.richTextBox1.Text = ("Account Creation   : " + status.ToString() + "\r\n"
                                    + "Username is        : " + username + "\r\n"
                                    + "Password is        : " + password + "\r\n"
                                    + "Email              : " + email);
    

    I did try to add a web.config the same as the ASP.NET Web Application but this failed. I did not even think of putting the configuration into app.config untill today. Funny how the brain works when trying to solve a problem.

    Password Hashing and Salting is all handled by the default MembershipProvider Class that is built into .NET. No need to do any crazy Encoding Hashing and Salting.

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

Sidebar

Related Questions

I guess this is a continuation of the last question I asked: bulk insert
If anyone read my last question, this is somewhat of a continuation of it.
This question is a continuation of my last one, regarding How to make Ruby
In continuation of this question . Does VB.NET supports virtual events?
So this is a continuation from my last question - So the question was
Fairly rubbish with PHP, this is a continuation on from my last question .
This is a continuation question from a previous question I have asked I now
This is a continuation of my question about reading the superblock . Let's say
This is in continuation with the question posted here: Finding the center of mass
This is a continuation of this question: Original Question (SO) The answer to this

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.