tags:

views:

30

answers:

4

hi,

In my MVC application I am reading the Membership/Profile/Role provider's connection string from web.config. In web.config I am writing this connection string at runtime. Now the problem is, if I update the web.config at run time, then each time my application will get restarted, it will slow down my application.

So I want to read the Membership/Profile/Role provider's connection string from any external file, other then web.config. Because if that external file is updated at run time, will not cause the application restart .

So please suggest me the way to read the connection string for role provider from external file .

Thanks in Advance Aayushi

A: 

Can I get the connection string for role provider from external file , but not from web.config

Aayushi
A: 

The SqlMembershipProvider relies on the web.config to retrieve connection string settings, and will throw an exception of the connection string is not provided via the ASP.NET configuration model.

That said, SqlMembershipProvider is not a sealed class. You could override its initialization behavior to achieve an effect similar to what you describe.

If you have a finite number of connection strings, as might be the case if you are trying to manage connection strings at different stages (e.g., dev, test, production, etc.), you might include all your connection strings in your web.config, each with its own name, and implement some runtime logic to switch between them in a custom provider.

public class CustomSqlMembershipProvider : SqlMembershipProvider
{
    public override void Initialize(string name, NameValueCollection config)
    {
        string connStringName = // retrieve from wherever you please...
        config["connectionStringName"] = connStringName;
        base.Initialize(name, config);
    }
}

The limitation of this approach is clear if you need to support arbitrarily many connection strings. Even so, you can still build a custom membership provider with behavior like the SqlMembershipProvider via inheritance if you override the Initialize method and sufficiently replace its internal behavior.

Good luck.

kbrimington
A: 

Hi,

thanks for your response. I am using MySql , so I have to inherit the class from MySQLMembershipProvider like I have written below but in that initialzie method I am not able to acceess MYSql base class method "initiliae":

    public class CustomSqlMembershipProvider :MySQLMembershipProvider
    {
      public override void Initialize(string name, NameValueCollection configs)
      {
       base.Initialize(name, configs); // this is not working with MySQLMemberShipProvider
      }
    }

SO how can access the base class "Initialize" method of MySQLMemberShipProvider. (base.Initialize()) is not working.

Thanks Aayushi

Aayushi
A: 

Hi,

thanks for your response. I am using MySql , so I have to inherit the class from MySQLMembershipProvider like I have written below but in that initialzie method I am not able to acceess MYSql base class method "initiliae":

    public class CustomSqlMembershipProvider :MySQLMembershipProvider
    {
      public override void Initialize(string name, NameValueCollection configs)
      {
       base.Initialize(name, configs); // this is not working with MySQLMemberShipProvider
      }
    }

SO how can access the base class "Initialize" method of MySQLMemberShipProvider. (base.Initialize()) is not working.

Thanks Aayushi

Aayushi