Security Blocks with FileConfigurationSource

Topics: Security Application Block
Nov 17, 2009 at 11:06 AM

Hi,

I am using custom configuration through a FileConfigurationSource.

I am able to use the Database and Logging application blocks perfectly well.

When I try to use the security application blocks, as soon as I enter Memership.Authenticate, i get an error saying 'unable to connect to SQL Server' httpException.

I am using a facade as follows for my other application blocks.

Do I need to create a facade for the security application blocks too? If so, can you please guide me?

 

{
    public static partial class AppHelper
    {

        static FileConfigurationSource _CBSAppBlocksSConfigurationSource;

        private static FileConfigurationSource CBSAppBlocksSConfigurationSource
        {
            get
            {
                if (AppHelper._CBSAppBlocksSConfigurationSource == null)
                {
                    AppHelper._CBSAppBlocksSConfigurationSource = new FileConfigurationSource(Constants.ApplicationBlocks.CONFIGURATION_FILE_NAME);
                }
                return AppHelper._CBSAppBlocksSConfigurationSource;
            }

        }


        public static Database GetDB(string connStr)
        {
            DatabaseProviderFactory CBSDatabaseProviderFactory = new DatabaseProviderFactory(CBSAppBlocksSConfigurationSource);
            Database db = CBSDatabaseProviderFactory.Create(connStr);
            return db;
        }



        public static void WriteLog(LogEntry ale)
        {
            LogWriterFactory CBSLogWriterFactory = new LogWriterFactory(AppHelper.CBSAppBlocksSConfigurationSource);
            LogWriter lw = CBSLogWriterFactory.Create();
            
            lw.Write(ale);
        }


    }
<font size="2">

 

</font>

 

<font size="2">

 

</font>

 

Nov 17, 2009 at 11:08 AM

Oh, and I am using the same code from the BugSmak example in the HOL. The BugSmak example works fine on the same machine. Of course, it does not have a custom configuration file.

Nov 17, 2009 at 12:51 PM

OK, I have figured out that Membership uses the default machine configuration, if an app.config is not present.

I need to change this so that the Membership now uses my configuration file and creates the requisite MembershipProvider.

Can you please tell me how?

 

Nov 18, 2009 at 7:14 AM

Hi,

Have you tried adding the membership config sections to your external config file? Or even in the app.config of your hosting app.?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Nov 18, 2009 at 9:09 AM

Hi,

 

Thanks for the reply.

I have done that. 

My problem is this:

For example when i want to create a Database object i use the following helper method:

 public static Database GetDB(string connStr)
        {
            DatabaseProviderFactory CBSDatabaseProviderFactory = new DatabaseProviderFactory(CBSAppBlocksSConfigurationSource); // CBSAppBlocksSConfigurationSource is the custom configuration source.
            Database db = CBSDatabaseProviderFactory.Create(connStr);
            return db;
        }

This retrieves the configuration settings from the custom configuration file and gives me the Database object.

I do not know how to write the helper method to obtain a Membership object which will be constructed using the custom configuration settings in a custom configuration file.
Currently, it is being created using the default configuration file as my client does not have an app.config. (Since my config file is, to borrow Tom Hollander's phrase,  owned by my DLL and I want to keep it that way.) 
If i move the app settings to the client app.config file, everything works fine.

Regards,
Parag.