Bryan
Bryan

Reputation: 857

Is there a way to programmatically set the connection string for ASP.NET Universal Providers?

I'm looking to deploy a solution to Azure that uses the ASP.NET Universal Providers. I want to store my connection strings in Azure config instead of in the web.config so I can change them without redeploy. I had thought about loading from settings and adding to the ConfigurationManager.ConnectionStrings collection but that is readonly. There are reflection hacks to overcome this, but that doesn't seem like the right way to go. I also was thinking about deriving from the provider classes to create my own provider classes that can set the connection string, but I don't see a property to set to override the connection string. Any ideas on a way to use the providers but not have the connection string in my web.config?

Upvotes: 4

Views: 811

Answers (1)

Tom
Tom

Reputation: 1611

I would suggest you put the settings in the Azure config file and then write a startup task or in the WebRole.cs OnStart you can access the IIS Management API's and update the web.config file in there with the correct connection string. That way you aren't having to get programmatic access to the connection string but still do what you want.

You can check out this blog post for some samples of using the API's althought it isn't doing what you are wanting to:

http://blogs.msdn.com/b/tom/archive/2011/02/18/installing-and-using-an-httpmodule-in-windows-azure.aspx

Upvotes: 1

Related Questions