Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1010953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:09:42+00:00 2026-05-16T09:09:42+00:00

I would like to have a variable defined in my web.config that I can

  • 0

I would like to have a variable defined in my web.config that I can use in multiple places within my web.config file (and other config files). It’s probably easier to explain by example …

web.config

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
    </appSettings>
    <system.web>

    ...

    <system.serviceModel>
        <client>
            <endpoint
                address="net.tcp://localhost/AuthService"
                binding="netTcpBinding"
                contract="MyServices.Contracts.IAuthService"
                name="#{AppSettings.AuthServiceEndPoint}"
                bindingConfiguration="netTcpBindingConfig"
            />

        </client>
    </system.serviceModel>
</configuration>

windsor.config

<?xml version="1.0" encoding="utf-8" ?>
<castle>
    <components>

        ...

        <component
            id="AuthProvider"
            service="MyServices.Client.IAuthProvider, MyServices.Client"
            type="MyServices.Client.AuthProvider, MyServices.Client"
            lifestyle="transient">
            <parameters>
                <endpoint>#{AppSettings.AuthServiceEndPoint}</endpoint>
            </parameters>
        </component>

    </components>
</castle>

Is this possible?


Edit (a bit more information)

I already have the ability to access the AppSettings from my windsor.config file (which is actually processed by castle windsor and a custom XmlInterpreter.

The real question is can I do this in my web.config?

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
    </appSettings>
    <system.web>

    ...

    <system.serviceModel>
        <client>
            <endpoint
                address="net.tcp://localhost/AuthService"
                binding="netTcpBinding"
                contract="MyServices.Contracts.IAuthService"
                name="#{AppSettings.AuthServiceEndPoint}"
                bindingConfiguration="netTcpBindingConfig"
            />

        </client>
    </system.serviceModel>
</configuration>

ie – access variable in my <appSettings> from other parts of my web.config file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:09:43+00:00Added an answer on May 16, 2026 at 9:09 am

    Here I go answering my own question again :-S

    I solved this by writing a NetTcpServiceLocator …

    public interface INetTcpServiceLocator
    {
        EndpointAddress GetAddress(Type serviceType);
    }
    

    … along with a custom config section handler which also implements the above interface and reads in the following config section …

    <services>
        <service contract="My.Services.TestService.Contracts.ITestService" address="net.tcp://localhost/TestService" />
    </services>
    

    Then I created a proxy for each service …

    public class TestServiceProxy : ITestService
    {
        public SomeInformation GetSomeInformation(SomeParams @params)
        {
            using (var factory = new NetTcpServiceFactory<ITestService>())
            {
                var service = factory.Service;
                return service.GetSomeInformation(@params);
            }
        }
    }
    

    My Controller has a dependency on a Service, which has a dependancy on ITestService. All this is glued together with Castle Windsor and by using property dependency injection.

    So, my controller calls it’s Service, which in turn calls the ITestService (in this case a proxy, which gets it’s endpoint from the custom section handler).

    The custom section handler (which is also the INetTcpServiceLocator) has a windsor lifestyle of “perWebRequest”, so it gets called by the framework and web.config is read into an array in memory. When the service proxy is called, it then just pulls the relevant endpoint based on the contract type.

    It’s all driven by the type of the contract, so there is no need to have any variables in web.config anymore.

    I’ve gone for a code based solution, as I don’t use a build process locally, only when I submit my code to subversion does the build process kick in on our build server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have pom.xml that contains defined values. I would like to use one of
I would like to have a variable (or #define ) in C++ source that
I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all
I would like to have a shell variable that could be dynamically run every
If I have a connection string defined in my web.config file, how do I
I would like to have my script accepting variable arguments. How do I check
I would like to have the $ (dollar sign) which indicates a php variable
I would like to have a random number generated based of a variable called
I have a variable in my makefile I would like to either unset or
I have a variable of type sbyte and would like to copy the content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.