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 597657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:18:15+00:00 2026-05-13T16:18:15+00:00

I have an asp.net web app that uses forms-based authentication, a SqlMembershipProvider (using an

  • 0

I have an asp.net web app that uses forms-based authentication, a SqlMembershipProvider (using an encrypted password format), and a SqlRoleProvider. I need to know if it’s possible to administer the users (create new users, assign them to roles, etc.) from a windows application – the powers that be don’t want any administrative functionality in the web app itself.

Here is the membership provider definition from web.config:

<membership defaultProvider="MyProvider">
  <providers>
    <add name="MyProvider"
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="MyConnectionString"
         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="true"
         applicationName="/MyWebApp"
         requiresUniqueEmail="true"
         passwordFormat="Encrypted"
         maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="7"
         minRequiredNonalphanumericCharacters="1"
         passwordAttemptWindow="10"
         passwordStrengthRegularExpression=""/>
  </providers>
</membership>

And the role manager definition:

<roleManager enabled="true" defaultProvider="MyRoleManager">
  <providers>
    <add name="MyRoleManager"
         type="System.Web.Security.SqlRoleProvider"
         connectionStringName="MyConnectionString"
         applicationName="/MyWebApp" />
  </providers>
</roleManager>

And here is the machineKey definition (necessary to be able to use encrypted passwords):

<machineKey
    validationKey="BC50A82A6AF6A015C34C7946D29B817C00F04D2AB10BC2128D1E2433D0E365E426E57337CECAE9A0681A2C736B9779B42F75D60F09F142C60E9E0E8F9840DB46"
      decryptionKey="122035576C5476DCD8F3611954C837CDA5FE33BCDBBF23F7"
      validation="SHA1"
      decryption="AES"/>

So, obviously, I have a Sql Server database that contains the users and roles for the web app. I’d like to create a separate windows app that references the web app assembly, and use the configured MembershipProvider, RoleProvider, and machineKey to create users, assign users to roles, etc. If that’s not possible, I can duplicate the configuration settings from web.config within the windows app. But I don’t know how to do this either.

Am I way out of line thinking that this is possible? I’ve tried googling for a solution, but the signal-to-noise ratio is really bad.

  • 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-13T16:18:16+00:00Added an answer on May 13, 2026 at 4:18 pm

    I’ve come up with a solution, based on the other answers (who both got +1), and some other sites out there.

    First, I created Application Config file (app.config). It mirrors exactly what is found in web.config from the web app, with the exception of how the connection string was handled:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    
      <configSections>
        <section name="connectionStrings" type="System.Configuration.ConnectionStringsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
      </configSections>
    
      <connectionStrings>
        <add name="MyConnectionString"
             connectionString ="SERVER=abc;UID=def;PWD=hij;Initial Catalog=klm;MultipleActiveResultsets=True"/>
      </connectionStrings>
    
      <system.web>
    
        <membership defaultProvider="MySqlMembershipProvider">
          <providers>
            <add name="MySqlMembershipProvider"
                 type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                 connectionStringName="MyConnectionString"
                 enablePasswordRetrieval="false"
                 enablePasswordReset="true"
                 requiresQuestionAndAnswer="true"
                 applicationName="/MyWebApp"
                 requiresUniqueEmail="true"
                 passwordFormat="Encrypted"
                 maxInvalidPasswordAttempts="5"
                 minRequiredPasswordLength="7"
                 minRequiredNonalphanumericCharacters="1"
                 passwordAttemptWindow="10"
                 passwordStrengthRegularExpression=""/>
          </providers>
        </membership>
    
        <roleManager enabled="true" defaultProvider="MySqlRoleManager">
          <providers>
            <add name="MySqlRoleManager"
                 type="System.Web.Security.SqlRoleProvider"
                 connectionStringName="MyConnectionString"
                 applicationName="/MyWebApp" />
          </providers>
        </roleManager>
    
        <machineKey
          validationKey="BC50A82A6AF6A015C34C7946D29B817C00F04D2AB10BC2128D1E2433D0E365E426E57337CECAE9A0681A2C736B9779B42F75D60F09F142C60E9E0E8F9840DB46"
          decryptionKey="122035576C5476DCD8F3611954C837CDA5FE33BCDBBF23F7"
          validation="SHA1"
          decryption="AES"/>
      </system.web>
    
    </configuration>
    

    Then I created a helper class that provides access to two singletons: a MembershipProvider and a RoleProvider. This turned out to be easier than I thought, once I knew how to do it:

    using System.Configuration;
    using System.Reflection;
    using System.Web.Security;
    
    namespace WebAdminViaWindows
    {
        internal static class Provider
        {
            private static readonly string assemblyFilePath = Assembly.GetExecutingAssembly().Location;
    
            static Provider()
            {
                Membership = CreateMembershipProvider();
                Role = CreateRoleProvider();
            }
    
            public static MembershipProvider Membership { get; private set; }
            public static RoleProvider Role { get; private set; }
    
            private static MembershipProvider CreateMembershipProvider()
            {
                var config = ConfigurationManager.OpenExeConfiguration(assemblyFilePath);
    
                var systemWebGroup = config.SectionGroups["system.web"];
                if (systemWebGroup == null)
                {
                    throw new ConfigurationErrorsException("system.web group not found in configuration");
                }
    
                var membershipSection = systemWebGroup.Sections["membership"];
                if (membershipSection == null)
                {
                    throw new ConfigurationErrorsException("membership section not found in system.web group");
                }
    
                var defaultProviderProperty = membershipSection.ElementInformation.Properties["defaultProvider"];
                if (defaultProviderProperty == null)
                {
                    throw new ConfigurationErrorsException("defaultProvider property not found in membership section");
                }
    
                var defaultProviderName = defaultProviderProperty.Value as string;
                if (defaultProviderName == null)
                {
                    throw new ConfigurationErrorsException("defaultProvider property is not a string value");
                }
    
                var providersProperty = membershipSection.ElementInformation.Properties["providers"];
                if (providersProperty == null)
                {
                    throw new ConfigurationErrorsException("providers property not found in membership section");
                }
    
                var providerCollection = providersProperty.Value as ProviderSettingsCollection;
                if (providerCollection == null)
                {
                    throw new ConfigurationErrorsException("providers property is not an instance of ProviderSettingsCollection");
                }
    
                ProviderSettings membershipProviderSettings = null;
    
                foreach (ProviderSettings providerSetting in providerCollection)
                {
                    if (providerSetting.Name == defaultProviderName)
                    {
                        membershipProviderSettings = providerSetting;
                    }
                }
    
                if (membershipProviderSettings == null)
                {
                    if (providerCollection.Count > 0)
                    {
                        membershipProviderSettings = providerCollection[0];
                    }
                    else
                    {
                        throw new ConfigurationErrorsException("No providers found in configuration");
                    }
                }
    
                var provider = new SqlMembershipProvider();
                provider.Initialize("MySqlMembershipProvider", membershipProviderSettings.Parameters);
                return provider;
            }
    
            private static RoleProvider CreateRoleProvider()
            {
                var config = ConfigurationManager.OpenExeConfiguration(assemblyFilePath);
    
                var systemWebGroup = config.SectionGroups["system.web"];
                if (systemWebGroup == null)
                {
                    throw new ConfigurationErrorsException("system.web group not found in configuration");
                }
    
                var roleManagerSection = systemWebGroup.Sections["roleManager"];
                if (roleManagerSection == null)
                {
                    throw new ConfigurationErrorsException("roleManager section not found in system.web group");
                }
    
                var defaultProviderProperty = roleManagerSection.ElementInformation.Properties["defaultProvider"];
                if (defaultProviderProperty == null)
                {
                    throw new ConfigurationErrorsException("defaultProvider property not found in roleManager section");
                }
    
                var defaultProviderName = defaultProviderProperty.Value as string;
                if (defaultProviderName == null)
                {
                    throw new ConfigurationErrorsException("defaultProvider property is not a string value");
                }
    
                var providersProperty = roleManagerSection.ElementInformation.Properties["providers"];
                if (providersProperty == null)
                {
                    throw new ConfigurationErrorsException("providers property not found in roleManagerSection section");
                }
    
                var providerCollection = providersProperty.Value as ProviderSettingsCollection;
                if (providerCollection == null)
                {
                    throw new ConfigurationErrorsException("providers property is not an instance of ProviderSettingsCollection");
                }
    
                ProviderSettings roleProviderSettings = null;
    
                foreach (ProviderSettings providerSetting in providerCollection)
                {
                    if (providerSetting.Name == defaultProviderName)
                    {
                        roleProviderSettings = providerSetting;
                    }
                }
    
                if (roleProviderSettings == null)
                {
                    if (providerCollection.Count > 0)
                    {
                        roleProviderSettings = providerCollection[0];
                    }
                    else
                    {
                        throw new ConfigurationErrorsException("No providers found in configuration");
                    }
                }
    
                var provider = new SqlRoleProvider();
                provider.Initialize("MySqlRoleManager", roleProviderSettings.Parameters);
                return provider;
            }
        }
    }
    

    At this point all that’s needed is to access the Membership and Role properties of the Provider class. As an example, the following prints out the first 10 users and their roles:

    int total;
    foreach (MembershipUser user in Provider.Membership.GetAllUsers(0, 10, out total))
    {
        var sb = new StringBuilder();
        sb.AppendLine(user.UserName);
        foreach (var role in Provider.Role.GetRolesForUser(user.UserName))
        {
            sb.AppendLine("\t" + role);
        }
    
        Console.WriteLine(sb.ToString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Like I mentioned in my edit, I just lacked the… May 14, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer You should use #pragma pack before including the headers of… May 14, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer ^activity/(?P<info>\d+)/$ will only match something like 'activity/42/' and the number… May 14, 2026 at 7:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.