Custom App.Config file for Serviced Component

I have come across this question few times this week so I though to start this whole 'blogging' with. Developers want to take advantage of the app.config file for the COM+ applications, but they are not available for dll? What now? Well as the hosting process is dllhost.exe, one could create app.config file for dllhost and put it in the %windir%/System32. Not really good solution is it? What is now you install something on the machine and someone thought about the same thing and they copy there app.config file there. Your application breaks...

Windows XP and 2003 provides a nice solution for this using the 'Application Base Directory' property of the COM+ Application.

So how to use it now? First step is to create an application.manifest file and copy it to the folder that you want to use as the base for your application. The content of the file is very simple, just copy the text from below to a notepad and save it as 'application.manifest'.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"/>

Now, create your app.config file for example something like below.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
  <add key="ConfigData" value="My Custom AppSetting!" />
 </appSettings>
</configuration>

Save this file to the same folder as the manifest file, NOTE the name of this file needs to be application.config!!!!

Now you are ready to configure your COM+ application. So, open you Component Services MMC and find your application.

After you have located your COM+ application, right click the application and go to 'Properties' and 'Activation' Tab.

At the bottom of this tab, you should be able to find an option for 'Application Root Directory'. Browse or copy paste the path that you saved the 2 files created earlier, click Apply, click OK and you are done!

Note: If you application is running you need to stop it for the change to take place and the AppDomain of the components BaseDirectory will return you this value!

Now, in your serviced component you can access the application specific configuration file by simply using System.Configuration.ConfigurationSettings.AppSettings["ConfigData"].

Filed under: System.EnterpriseServices

 

Original Link: http://blogs.msdn.com/heikkiri/archive/2005/11/10/...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值