Separate .config file

B

Blasting Cap

I am working on a web app that I want to be able to use a separate
config file on, in addition to the web.config file that's already
working in the application.

If I put the following in the web.config file (VS 2005, Framework 2.0),
I can retrieve the values fine:

<appSettings>
<add key="fileInputFolder" value="C:\National City Downloads\test"/>
<add key="fileTransaction" value="\Transactions\"/>
<add key="TimerInterval" value="20000"/>
<add key="Conn" value ="Data Source=dellserver\sql2000;Initial
Catalog=CIC_BankModel;Persist Security Info=True;User
ID=sa;Password=adminsql"/>
</appSettings>

I retrieve the value with this line in the codefile in one of the apps
on the page:

Session("MyExchangeServer") =
WebConfigurationManager.AppSettings("fileInputFolder").ToString

The placement of the above appsettings line is right after the
</system.web> in the web.config file, and immediately before the
<system.net> line.

Any of those values can be read with no problem if they're in the
web.config file.

I added a new item to my project, app.config.

It looks like this:

<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings>
<add key="fileInputFolder" value="C:\National City Downloads\test"/>
<add key="fileTransaction" value="\Transactions\"/>
<add key="TimerInterval" value="20000"/>
<add key="Conn" value ="Data Source=dellserver\sql2000;Initial
Catalog=CIC_BankModel;Persist Security Info=True;User
ID=sa;Password=adminsql"/>
</appSettings>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false" />
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>

</configuration>


It returns this message when I try to load the page.

The format of a configSource file must be an element containing the name
of the section. (C:\Inetpub\wwwroot\test\App.config line 10)

The only thing I have changed from the original app.config file was
where appSettings was already in the file, in the form <appSettings/>.
Where you see the <appSettings> and the 3-4 lines followed by the
</appSettings>, I simply replaced it.

The exact error on the page is:

Configuration Error
Description: An error occurred during the processing of a configuration
file required to service this request. Please review the specific error
details below and modify your configuration file appropriately.

Parser Error Message: The format of a configSource file must be an
element containing the name of the section.

Source Error:


Line 8: \Windows\Microsoft.Net\Framework\v2.x\Config
Line 9: -->
Line 10: <configuration>
Line 11: <appSettings>
Line 12: <add key="fileInputFolder" value="C:\National City
Downloads\test"/>


Source File: C:\Inetpub\wwwroot\test\App.config Line: 10


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42;
ASP.NET Version:2.0.50727.210


Any idea what I am doing wrong on this? I'd like to do some more with
this alternate config file, but I'm just trying to get the simple stuff
to work, before I do anything else.

Thanks,

BC
 
P

PlatinumBay

Blasting Cap,

The use of the ConfigSource attribute is as follows:

Each section that supports configSource gets specified as
<membership configSource="config\membership.config"/>

In the membership.config (name doesn't matter), you would specify only the
membership section.

<membership defaultProvider="CustomSqlMembershipProvider"
userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="CustomSqlMembershipProvider"
connectionStringName="<connString>"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
applicationName="<appname>"
requiresUniqueEmail="false"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="5"
passwordFormat="Hashed"
enablePasswordRetrieval="false"
enablePasswordReset="true"/>
</providers>
</membership>

Here is some more info:
http://weblogs.asp.net/fmarguerie/a...onfigsource-to-split-configuration-files.aspx

Hope this helps,


Steve
 
B

Blasting Cap

Steve -

thanks for the assistance. With your example and the link, I finally
saw what I was doing.....

Thanks!!

BC
 
J

Juan T. Llibre

re:
!> I want to be able to use a separate config file on, in addition to
!> the web.config file that's already working in the application.

To use a separate config file for the appsettings section of web.config, use :

<appSettings configSource="somefile.config"/>

To enable the configuration to be recognized on any change to "somefile.config",
edit machine.config, in the <configSections> section, and edit <section name="appSettings" ... >,
adding : restartOnExternalChanges="true"

That'd make it :

<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="true"
requirePermission="false" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top