I have implemented a DNN module that uses a user-defined control (this user-defined control has implemented GoogleAnalytics tracking for our own use).
The control needs to access a config file in order to grab the configuration settings of our google analytics account. For example, the account code (UA-dddddd-dd), etc.
My question: Since I'm installing the module on DotNetNuke, where is the proper location to put the config file at OR what config file would it be accessing by default?
The piece of code in the control that attempts to access the config file is provided below:
string path = Assembly.GetExecutingAssembly().CodeBase;
FrameworkConfig.instance = new FrameworkConfig(ConfigurationManager.OpenMappedMachineConfiguration(new ConfigurationFileMap(path + ".config")));
note: FrameworkConfig
is a wrapper class for System.Configuration
object.
In short, I need to know what does Assembly.GetExecutingAssembly().CodeBase
return when called through a DNN module? other alternatives?
If you add keys to the appsettings section of the DNN site's web.config, you can retrieve them using:
DotNetNuke.Common.Utilities.Config.GetSetting("settingname");
However, it is a better practice, and makes sense in this case to create a Settings
control in your module and to store the information there.
You do this by creating an ascx control that inherits from DotNetNuke.Entities.Modules.ModuleSettingsBase
and stores settings in the base Settings Dictionary for you module.
Your other module view controls can access the settings via a similar Dictionary
object called Settings
that is part of the ModuleUserControlBase
class.
For an example of how to use module settings, check out this DNN7 tutorial video and article. A sample project with all the code is in the Related Files section of the article.