Custom Configuration Items for Web Parts

David Speed asked on January 16, 2015 04:45

Hello,

We are developing custom Kentico web parts that make web service calls. What we'd like to do, if at all possible, is to avoid polluting the global Kentico web.config file with settings pertaining to our custom web parts. That way it makes moving servers / handling Kentico upgrades less of a pain.

Ideally, we would have a separate web.config file at the sub directory level where our web parts are stored (CMSWebParts/ClientName/ folder), but it's my understanding that the config file used in the web part would be the config file at the directory level of the page that the web part is being called from (a simple .NET aspx / user control solution test seems to confirm this to me).

I realise that one option would be to expose all the settings (bindings etc.) to Kentico web part properties that can be set when the web part is dropped on a template, but that doesn't seem ideal to me as these properties would be global across the site and not changing from web part to web part on the site.

Is there a solution that anyone has implemented or can think of that would separate our custom configuration settings from the global web.config?

Thanks in advance.

Recent Answers


Brenden Kehren answered on January 16, 2015 06:04

Don't create your settings in the web.config file. Use custom website Settings. Create a custom module within the UI and add settings categories and keys to it. You can then gather your values dynamically at runtime and change them on the fly if you need to without having to change your code or a config file.

Take a look at the documentation.

2 votesVote for this answer Mark as a Correct answer

Joel Dahlin answered on January 16, 2015 06:06

Have you thought about using the configSource or file properties to reference an external config file specifically for your webpart? It would still require you updating the global Kentico web.config file, but it would only be one property update.

Learn more here, https://learnable.com/books/the-asp-net-2-0-anthology-101-essential-tips-tricks-hacks/preview/how-can-i-simplify-my-web-config-file-a64852b

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.