Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

TUTORIAL: Loading configuration settings in a page plugin
heldersolutions
#1 Posted : Sunday, July 10, 2011 12:54:56 PM(UTC)
Rank: Newbie
Groups: Registered

Joined: 4/28/2011(UTC)
Posts: 8
Location: Netherlands, Beverwijk
Hi there,

The other day I needed to incorporate settings in a custom made Page Plugin.

I didn't want to edit the web.config of Kooboo, because that would create a lot of rubbish in the end.

1) I created a Page Plugin specific configuration file, called my.config. As you can see, the structure of the configuration file looks just like a regular .net configuration file.

Code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="foo" value="bar" />
  </appSettings>
</configuration>


2) I uploaded my.config into the root of the file manager under Development - Files.

3) In code, I can now reference to my.config by doing this:

Code:

var path = Path.Combine(pageViewContext.PageRequestContext.Site.PhysicalPath, "Files", "my.config");
var configMap = new ExeConfigurationFileMap
{
    ExeConfigFilename = path
};

var config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
var section = (AppSettingsSection)config.GetSection("appSettings");

var response = pageViewContext.ControllerContext.HttpContext.Response;
response .Write("Value of foo = " + section.Settings["foo"].Value + "<br />");


That's all there is to it. Enjoy!
1 user thanked heldersolutions for this useful post.
jifeng on 7/11/2011(UTC)
jifeng
#2 Posted : Sunday, July 10, 2011 2:21:17 PM(UTC)
Rank: Administration
Groups: Administrators, Registered

Joined: 9/3/2009(UTC)
Posts: 1,552
Location: Xiamen China
In the coming version, there have custom settings(key-value) in the site setting. It will be helpful in this case.
Regards,

Jifeng Huang

Kooboo Team

Microsoft ASP.NET MVP
heldersolutions
#3 Posted : Sunday, July 10, 2011 2:58:49 PM(UTC)
Rank: Newbie
Groups: Registered

Joined: 4/28/2011(UTC)
Posts: 8
Location: Netherlands, Beverwijk
Good to hear this functionality is added in the coming version! :-)

The code supplied might provide a solution until the coming version is released.

Also, it provides an alternative for those stuck with the current version.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.056 seconds.