2003-02-21

Smart Client Config

You can use application configuration files with smart clients over the web. Say you want to store a setting in an XML config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="WebServiceUrl" value="http://mypublicserver/smartclientservice.asmx?wsdl" />
</appSettings>
</configuration>


Just save this as a file named after you EXE with ".config" appended to it: smartclient.exe.config
To access the setting from within your app use the ConfigurationSettings class:

_service.Url = ConfigurationSettings.AppSettings["WebServiceUrl"].ToString();

The last thing you must do before this works is modify the web.config file for your web app. You'll need to allow the app to serve up .config files:


<configuration>
<system.web>
<httpHandlers>
<!-- Except for web.config allow any config to be served up -->
<remove verb="*" path="*.config" />
<add verb="*" path="web.config" type="System.Web.HttpForbiddenHandler"/>
</httpHandlers>
</system.web>
</configuration>


With my last post I described a problem with bogus web requests. On the positive side it yielded a solution to another problem I was having, loading config files over the web.


0 Comments:

Post a Comment

<< Home