Separate .config file

Discussion in 'ASP .Net' started by Blasting Cap, Jun 5, 2007.

  1. Blasting Cap

    Blasting Cap Guest

    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
     
    Blasting Cap, Jun 5, 2007
    #1
    1. Advertising

  2. Blasting Cap

    PlatinumBay Guest

    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

    "Blasting Cap" <> wrote in message
    news:...
    >
    > 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
     
    PlatinumBay, Jun 5, 2007
    #2
    1. Advertising

  3. Blasting Cap

    Blasting Cap Guest

    Steve -

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

    Thanks!!

    BC



    PlatinumBay wrote:
    > 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
    >
    > "Blasting Cap" <> wrote in message
    > news:...
    >> 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

    >
    >
     
    Blasting Cap, Jun 5, 2007
    #3
  4. 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" />



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Blasting Cap" <> wrote in message news:...
    >
    > 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
     
    Juan T. Llibre, Jun 5, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EvgueniB
    Replies:
    1
    Views:
    671
    Anthony Borla
    Dec 15, 2003
  2. Frank Fredstone
    Replies:
    1
    Views:
    466
    Jean-Francois Briere
    Jun 27, 2006
  3. CSharpner
    Replies:
    0
    Views:
    1,131
    CSharpner
    Apr 9, 2007
  4. Replies:
    1
    Views:
    582
  5. kampy
    Replies:
    9
    Views:
    371
    Steven D'Aprano
    Oct 19, 2012
Loading...

Share This Page