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 2, 2005 12:23 AM by ScottGu

Comments

# re: VS 2005 Intellisense in web.config files

Friday, December 2, 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 2, 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 2, 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 2, 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 6, 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.

# re: VS 2005 Intellisense in web.config files

Thursday, February 1, 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 4, 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