aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

Injecting the azure table storage connection string for Webhooks #140

Closed Sacratees closed 7 years ago

Sacratees commented 7 years ago

I am using the azure table storage for the one of our webhook sender service.

For this, the MS_AzureStoreConnectionString has to be set in the web.config file.

Now i need to get the above values from the key vault which can be done through custom implementation only.

I removed the "MS_AzureStoreConnectionString" key in my web.config.

And i have tried to inject the azure table storage connection string to the default web hook implementation as below in my startup class.

SettingsDictionary settings = new SettingsDictionary();

string connectionString = helper.getTableSrorageConnectionString();

ConnectionSettings connection = new ConnectionSettings("MS_AzureStoreConnectionString", connectionString);

settings.Connections.Add("MS_AzureStoreConnectionString", connection);

But I am facing the below issue while running my APP.

Please provide a Microsoft Azure Storage connection string with name 'MS_AzureStoreConnectionString' in the configuration string section of the 'Web.Config' file.

How can i inject the connection string to the default web hook implementation?

Kindly suggest the possible solution on this.

renjurajt commented 7 years ago

Following Implementation working for me

// Set Connection String for Asp Webhook
var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var connectionStringsSection = ConnectionStringsSection)configuration.GetSection("connectionStrings");
connectionStringsSection.ConnectionStrings["MS_AzureStoreConnectionString"].ConnectionString = "UseDevelopmentStorage=true;"
configuration.Save();
ConfigurationManager.RefreshSection("connectionStrings");
Sacratees commented 7 years ago

Thanks for your response.

Actually i don't want to persist the connection string in the web.config / app settings.

looking for the injection to the default webhooks.

Sacratees commented 7 years ago

The below snippet also worked for me. you have to add the below lines before config.InitializeCustomWebHooksAzureStorage() lines to be added.. ConnectionSettings value = new ConnectionSettings("MS_AzureStoreConnectionString", "connectionString") SettingsDictionary settings = config.DependencyResolver.GetSettings(); settings.Add("MS_AzureStoreConnectionString",value );

nulllogicone commented 7 years ago

I could solve it by adding the following lines before config.InitialiyeCustomWebHooksAzureStorage

            var constr = ConfigurationManager.ConnectionStrings["MyConnectionStringName"].ConnectionString;
            var value = new ConnectionSettings("MyConnectionStringName", constr);
            var settings = config.DependencyResolver.GetSettings();  
            settings.Connections.Add("MS_AzureStoreConnectionString", value);