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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:03:45+00:00 2026-05-22T00:03:45+00:00

My requirement is to create a framework that can consume standard ASP.NET Profile provider.

  • 0

My requirement is to create a framework that can consume standard ASP.NET Profile provider. The application contains two libraries, one for Profile access (saving and retrieving Profile using a ProfileBase class) – A framework class library, and the other one for defining properties for the Profile – Developer client class library which consumes the above framework class library.

The idea here is that the developers don’t need to know about the underlying profile implementation (in the framework class library), and all they have to do is to provide properties in a class so the profile can be set and get as expected.

My implementation is below.
(Please note that I have configured the authentication, connection strings and role providers successfully)

Web.config->

   <profile inherits="MyCompany.FrameworkLib.ProfileSettingsService, MyCompany.FrameworkLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=12ac5ebb7ed144" >
<providers>
    <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>
</profile>

   *Our design is not to specify profile properties in the web.config.

Implementation of MyCompany.FrameworkLib.ProfileSettingsService ->

public class ProfileSettingsService : ProfileBase, IProfileSettingsService
{
     "**Note that if I un-comment the below code Profile works as expected. I do not want this property to be here, but somehow discover it dynamically based on the values being passed to this class. How can I do this?.**"
    
    //[SettingsAllowAnonymous(false)]
    //public string HideTransactionButton
    //{
    //    get { return base["HideTransactionButton"] as string; }
    //    set { base["HideTransactionButton"] = value; }
    //}

    #region IProfileSettingsService Members

    public T Get<T>(string key, T defaultValue)
    {
        if (string.IsNullOrEmpty(key))
        {
            throw new ArgumentNullException("key");
        }

        object profileValue = null;

        try
        {
            profileValue = GetUserProfile().GetPropertyValue(key);
        }
        catch { }

        if (profileValue is T)
        {
            return (T)profileValue;
        }

        return defaultValue;            
    }

   
    public void Set<T>(string key, T value)
    {
        GetUserProfile().SetPropertyValue(key, value);
        GetUserProfile().Save();
    }

    public ProfileSettingsService GetUserProfile(string username)
    {
        return Create(username) as ProfileSettingsService;
    }


    public ProfileSettingsService GetUserProfile()
    {
        var userName = HttpContext.User.Identity.Name;
        
        if (userName != null)
        {
            return Create(userName) as ProfileSettingsService;
        }

        return null;
    }
    #endregion
}

implementation of MyCompany.ConsumeLib.ProfileContext ->

public class ProfileContext : IProfileContext
{
    #region IProfileContext Members

    [Dependency] //Note that I use Unity for DI
    public IProfileSettingsService ProfileSettingsService { get; set; }

    public string HideTransactionButton
    {
        get { return this.ProfileSettingsService.Get<string>("HideTransactionButton", "false"); }
        set { this.ProfileSettingsService.Set("HideTransactionButton", value); }
    }
  
    #endregion
   
}

So the question is how to get the Profile working without having to uncomment

//[SettingsAllowAnonymous(false)]
//public string HideTransactionButton
//{
//    get { return base["HideTransactionButton"] as string; }
//    set { base["HideTransactionButton"] = value; }
//}

in MyCompany.FrameworkLib.ProfileSettingsService

I need to be able to discover properties dynamically within ProfileSettingsService without having to explicitly specifying properties. In this way, developer doesn’t need to worry about maintaining properties in two libraries – (one in the frameworkLib, and the other one is in the ConsumeLib.)

  • 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-22T00:03:46+00:00Added an answer on May 22, 2026 at 12:03 am

    I have decided to take another approach to solver this problem. Unfortunately the way MS has designed the ProfileBase class there is no easy way to do this.

    There are 2 possible solutions. I use below ‘b’
    a. Add profile properties to Web.config and use T4 templates dynamically generate them.
    b. Have a look at the http://archive.msdn.microsoft.com/WebProfileBuilder. This will also dynamically generate profile properties at compile time.

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

Sidebar

Related Questions

I have a requirement to create a simple windows forms application that allows an
I have a requirement to create a multi level treeview in ASP.Net (with VB)
I have a requirement to create two different maps in C++. The Key is
If I have a requirement to create a data structure that has the following
For a project we have a requirement to create an interfacedefinition that will return
The requirement I have to implement is to create special views that look similar
I have to create an application for testing that is relatively simple. If a
I'm building a new ASP.NET MVC application (in C#) and one of the requirements
I have a requirement to create a simple database in Access to collect some
I have a requirement to create a windows form control which has to detect

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.