.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Appsettings config section in web.config cause WCFTestClient to fail

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :WCF
i have a WCf project, when i add the following code to the configuration file (Web.config): <configuration> <appSettings> <add key="hello" value="Monday" /> </appSettings> ..... ... .... i get this error when trying to debug: "Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information." when i drop the appsettings, the WCFTestClient opens. how do i define constants in the web.config if not in that way ?

View Complete Post

More Related Resource Links

Web deployment project - web.config section replacement does not add remove tag


I have a web application that is actually installed as a component of a third party site.  In some configurations, I need to remove certain connection strings and re-add them.  I'm replacing this web.config section with a xml file that includes the following:

      <remove name="MyOverridenConnection"/>
      <add connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDb;Data Source=MyServer" name="MyOverridenConnection"

For some reason the remove tag is left out during the substitution and I end up with the following in the installed config:

      <add connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDb;Data Source=MyServer" name="MyOverridenConnection"

Is there any way to issue removes in replaced sec

Custom config returns NULL section despite "proper" definition


I have defined a custom config section but when I try to get the section, it's always null.

I can't see what I'm missing. The only thing that I can might be an issue is that the code is part of a library project ina a solution with a main project, so not sure if the app.config has to be under the main project instead.

Below is my code, any ideas?

    public class CustomConfiguration : ConfigurationSection
        [ConfigurationProperty("keys", IsRequired = false)]
        public KeyCollection Keys
                return this["keys"] as KeyCollection;

    public class Key : ConfigurationElement
        [ConfigurationProperty("name", IsRequired = false)]
        public string Name
                return this["name"] as string;

        [ConfigurationProperty("value", IsRequired = false)]
        public string Value
                return this["value"] as string;

    public class KeyCollection : ConfigurationElementCollection
        public Key this[int index]
                return base.Base

Merge a section NameValueSectionHandler of two .config files (C#)

I need merge a section of type NameValueSectionHandler from two .config files (Main.config and Secundary.config in sample).

The Main.config has another sections like appsetings and others.


<?xml version="1.0" encoding="utf-8" ?>
        <section name=&q

ConfigurationManager.AppSettings not reading my app.config

I am having a frustrating issue that everyone tells me should be very simple to execute.
I'm using the new ConfigurationManager object from System.Configuration.dll which I have referenced in my project.  I do not have any compliation problems or warnings, yet I cannot get a single key value out of my app.config file.  My config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <add key="KeyName" value="KeyValue"/>

and am trying to just assign this to a string like this:

string path =  System.Configuration.ConfigurationManager.AppSettings["KeyName"];

not only does this invariably result in an empty string, but also when I step to this line in my code...System.Configuration.ConfigurationManager.AppSettings.AllKeys evaluates to {Dimensions:[0]} as if I don't even have an App.Config file.  What could I possibly be doing wrong!?!?!?!

Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we've added over the years, including the functionality for:

.ASP.NET Dynamic Data
.ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
.ASP.NET Chart Control (which now ships built-into ASP.NET V4)
What this means is that when you create a new "Empty ASP.NET application" project in VS 2010, you'll find that the new default application-level web.config file is now clean and simple:

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

NUnit and config files


Ive created an NUnit test project in my solution and have added 3 tests.  They all fail with the same error

SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.


SetUp : System.TypeInitializationException : The type initializer for 'Systems.Utils.ConstantHelpers' threw an exception.

  ----> System.NullReferenceException : Object reference not set to an instance of an object.

heres the test method

        public void CreateDataContext_ConnectionString_ReturnsDataCon

URL Rewrite causes AppSettings to Fail?


Hi there,

I just implemented basic URL rewriting to change a page from, for example, /member.aspx?id=123 to /member.aspx/erik.  That works and I'm happy with it.  However, I am now getting an error message that states "the connectionstring property has not been initialized".  Normally, I've been storing the connectionstring in web.config, and I access it with:

Dim Connect As SqlConnection = New SqlConnection
Dim ConnectString As String
ConnectString = ConfigurationManager.AppSettings("linktomysite")
Connect.ConnectionString = ConnectString

This is what I do on every other page of the site and it works fine.  The only way it will work on the page where I'm URL re-writing, however, is if I replace "ConfigurationManager.AppSettings("linktomysite")" with the actual connection string itself.  For security reasons, obviously I would prefer to keep that info out of the page.  What can I do?



Modifying connection String in Web config using Install Wizard



Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a lot of articles on how to do this and in particular this http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors,  heres part of my code where the errors are

using System;
using System.Configuration;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.DirectoryServices;

 void ConfigureDatabase(string targetSite, string targetVDir, string connectionString)
            // Retrieve "Friendly Site Name" from IIS for TargetSite
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSit

The ASP Column: What's in ASP.NET Config Files?


Even though you've been using ASP. NET for a while, how much do you really know about ASP. NET configuration files? While you've probably touched the Web. config file from time to time, there are some nuances involved in configuring ASP.

George Shepherd

MSDN Magazine September 2004

Razor View Engine and Add Namespace in Web.Config Problem



I am working on a MVC project with Razor view engine and I have the following:


This only works if I have on the same view the following:

  @using SquishIt.Framework;

However, on my Web.Config I have the following:


      <!-- Namespaces -->
        <add namespace="System"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="Microsoft.Web.Mvc"/>
        <add namespace="SquishIt.Framework"/>


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

How in web.config work in MVC



I would like to secure any URL below the http://MyServer/Admins and limit it to a specific role.

In webforms it was straight forward. I just put a child web.config in the /Admin/ folder and add <authorization>  <allow roles> tags to it.

How would be the equivalent technique in MVC?

Thank you,


pageParserFilterType in Web.config


Hi there,

I'm asking this question AFTER I've already solved my problem - I just wanted more info about it.

Each time I tried to create a ViewUserControl with a specific model template like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProject.Web.ContactFormContent>" %>

The control would not compile properly and intellisense would not show things like Html and ViewData.

However, when I add the attribute pageParserFilterType to the <pages> in web.config, everything works:

      pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc,
        Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

      pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc,

All my server-controls became unrecognized!!! like there's compilation error or web.config missing!



please help - the problem is in post subject.

I have lots of warnings with following text:

"Warning 10 Element 'HyperLink' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing. C:\Users\Pavel\Documents\Visual Studio 2010\WebSites\BioWebSite\ToScientist.aspx 26 18 C:\...\BioWebSite\" 

But web.confg is there! And there's no compilation error!

Site builds just fine. And If I upload it to my hoster - it works!


But with all these errors I cant add controls to pages - VS2010 adds hyperlink without ID, and intelisens stoped to work.

Strange, but in my other project (web-application) I have no such difficuty.

Need help with web.config security - Can't figure out where the security group is located in the ap



   We have sepeartate folder called Managers in one of our web apps. And there was a security build around that folder in a web config file as below

<?xml version="1.0"?>
        <allow roles="AllManagers"/>
        <deny users="*"/>

I couldn't figure out where this group located in the application. Usually all our groups are defined in Active directory but except this group. I am not sure if this is defined on the web server or some where in the app itself. Because in the process of figuring out I have changed it to <allow users="*"/> just to make sure if this is the group we are looking for and YES It is and I have access to it. So I need to find out where this is located and add myself as one of the users to this group.

Can any one help me with this mystery.

Thanks in advance,


Sharepoint Site Web Config elements Gets Deleted automatically


see i used to have a security filter settings in web config
security><requestFiltering><requestLimits maxAllowedContentLength="104857600"/></requestFiltering></security>
 but it gets deleted automatically after  i dont know why 
we tried to install something in our server yesterday it didn't worked and reverted it back to yesterdays stage( But i had updated the config files 3 weeks ago) 
but today i check the config files  these elements are  not there.

My system is 64 bit windows server 2008 with IIS 7 and MOSS 2007 SP2

Encrypting/Decrypting web.config sections in ASP.Net

The article Encrypting/Decrypting web.config sections in ASP.Net was added by ujjwaladatta on Thursday, August 26, 2010.

Encrypting/Decrypting web.config sections in ASP.Net using System.Configuration; using System.Web.Configuration; public partial class _Default : System.Web.UI.Page { protected void Encripting_Click(object sender, EventArgs e) { EncriptSection("appSettings"
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend