VS 2005 Intellisense in web.config files

I’ve seen a few questions about intellisense support for ASP.NET web.config files with VS 2005, and thought I’d blog a quick post to answer a few of them.

 

First the good news:

 

VS 2005 now supports intellisense for web.config files you add to your web project (yea!).  It uses the new XML editor (which btw is much better in VS 2005), and has a built-in schema for all of the built-in .NET Framework settings:

 

 

Now one annoying gotcha:

 

There is one gotcha to be aware of, though, that can sometimes cause intellisense for the web.config file to stop working in the IDE.  This happens when a default namespace is added to the root <configuration> element.  For example, like so:

 

            <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

           

This doesn’t cause any runtime problems – but it does stop intellisense completion happening for the built-in .NET XML elements in the web.config file. 

 

The bad news is that the built-in web admin tool (launched via the WebSite->ASP.NET Configuration menu item in VS 2005 and Visual Web Developer) always adds this xmlns namespace when it launches – so if you use this tool to manage users/roles you’ll end up having it added to your web.config file for you.

 

How to fix this gotcha:

 

To get intellisense back when you are editing the web.config file in the IDE, just delete the xmlns reference and have the root configuration element look like so:

 

<configuration>

 

Everything will then work fine again.

 

Hope this helps,

 

Scott

Published Friday, December 02, 2005 12:23 AM by ScottGu

Comments

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 5:01 AM by David Taylor
Nice tip Scott.

I had stumbled across the fact that the namespace was stopping intellisense working, but did not realize it was being reinserted by the admin tool!

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 5:04 AM by Edgardo Rossetto
I notice this a few days ago (upgrading a huge project from beta 2 to RTM), but there's still one problem, in my project I use the provider model, so I have defined a custom section inside <configuration>:

<configSections>
<sectionGroup name="system.web">
<section name="MyCustomSection"
type="MySection"
allowDefinition="MachineToApplication"
restartOnExternalChanges="true"/>
</sectionGroup>
</configSections>

and inside system.web

<MyCustomSection defaultProvider="SqlProvider">
<providers>
<add ... />
</providers>
</MyCustomSection>

This works just fine on runtime, but guess what: intellisense doesn't work anymore.

Furthermore, your custom section is marked as "invalid child".

Tricky? you bet.

Now if you add xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
to the <configuration> element the warning is removed, but again, no intellisense.

Bug? :(

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 5:26 AM by Paschal
Thanks Scott, works fine for me. One thing however is Intellisense doesn't seem to do good with the providers. I try with Sitemap tag and Intellisense don't show any attributes.

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 7:11 AM by Karl
So this is a bug that'll get fixed up in our juicy service release?

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 8:49 AM by Massimo Prota
I've found a definitive fix to this problem:
change in file %windir%\Microsoft.NET\Framework\v2.0.50727\ASP.NETWebAdminFiles\WebAdminPage.cs
in the SaveConfig method (line 93) the line
config.NamespaceDeclared = true;
with
config.NamespaceDeclared = false;

The solution and link to corrected file also on my blog (in italian)
http://blogs.ugidotnet.org/mprota/archive/2005/11/23/30392.aspx

It seems to works fine

# re: VS 2005 Intellisense in web.config files

Friday, December 02, 2005 10:54 AM by scottgu
Hi Edgardo,

Unlike for .aspx pages, the intellisense for web.config files is specificied statically and not dynamically (whereas with .aspx pages the engine will dynamically update the intellisense rules as you add controls into your project).

I know there is a file where you can add your own schema rules to generate intellisense. I'm not entirely sure where it is...but I know one is there...

Hope this helps,

Scott

# re: VS 2005 Intellisense in web.config files

Sunday, August 06, 2006 7:03 AM by Farshid Hosseini
Hi, The file is at: [drive name]:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\DotNetConfig.xsd Regards, Farshid

# re: VS 2005 Intellisense in web.config files

Wednesday, August 23, 2006 2:04 PM by Zach
Thanks, I had no clue where my intellisense went.

# Brennan&#8217;s Blog &raquo; Blog Archive &raquo; Visual Studio Tip #3: Delete the XMLNS attribute from your web.config

PingBack from http://brennan.offwhite.net/blog/2006/09/25/visual-studio-tip-3/

# Marcos Dell Antonio&#8217;s Blog &raquo; Blog Archive &raquo; .NET: Cad&ecirc; o Intellisense do Web.Config?

PingBack from http://www.marcosdellantonio.net/blog/index.php/2006/12/05/net-cad-o-intellisense-do-webconfig/

# re: VS 2005 Intellisense in web.config files

Thursday, December 07, 2006 10:42 AM by William Ramirez

Patches and patches, why doesn't microsoft just put something up in http://schemas.microsoft.com/.NetConfiguration/v2.0 ???

Is it like a way to torment people?, each time you edit the file with either IIS or the web setup it reinserts this crap.

# re: VS 2005 Intellisense in web.config files

Thursday, January 11, 2007 5:35 AM by Ray

Thanks-  That was really bugging me!

# re: VS 2005 Intellisense in web.config files

Thursday, February 01, 2007 7:18 PM by TRAVIS

I get messages about my web.config even though I have removed the xmlns element.  It apparently doesn't like the custom elements that we've added.  Do I -have- to create a schema for this?

# re: VS 2005 Intellisense in web.config files

Sunday, February 04, 2007 5:36 PM by ScottGu

Hi Travis,

I believe you need to create a schema for your custom elements I'm afraid to get intellisense.

Sorry!

Scott

# XML 04.03.04 released to public

Thursday, May 24, 2007 11:46 AM by Stefan Cullmann

XML 04.03.04 covers these issues: XML-5464 Search is now independent from the current HttpContext - works now also using Scheduler A job called by scheduler doesn’t run in any HttpC ...

# Writing my first WCF service on Vista

Thursday, July 05, 2007 10:04 AM by Infosys | Microsoft

Writing WCF service on IIS 7.0 on Vista

# VS 2005 Intellisense in web.config files

Monday, May 12, 2008 8:22 PM by Vincent Yang

Ref:weblogs.asp.net/.../432077.aspxI’veseenafewquestionsabouti...