Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

Visual Studio and <location> parsing in web.config


:P
On this page:

So here's a funky Visual Studio behavior: On my root Web site (which is mostly static) I have my web.config set up to handle the root site configuration in a separate <location> element in order not to force the settings of the root site down into the many, many virtual directories/applications that are running on the site. So the core layout looks like this:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="webConnectionConfiguration" type="System.Configuration.NameValueSectionHandler,System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="wwBanner" type="System.Configuration.NameValueSectionHandler,System,Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </configSections>
    <connectionStrings>
        <add name="WestWindAdmin" connectionString="server=.;database=WestWindAdmin;integrated security=true;" providerName=""/>
    </connectionStrings>
    <location inheritInChildApplications="false">
        <system.web>
            <compilation debug="true">
                <assemblies>
          <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>
            </compilation>
            <pages>
                <namespaces>
                    <add namespace="Westwind.Tools"/>
                    <add namespace="Westwind.Web.Controls"/>
                </namespaces>
            </pages>
            <trust level="Full"/>
            <authentication mode="Windows"/>
            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            </customErrors>
        </system.web>
        <system.webServer>
            <handlers>
                <add name="West West Wind Web Connection" path="*.wst" verb="*" modules="IsapiModule" scriptProcessor="c:\westwind\wconnect\wc.dll" resourceType="Unspecified"/>
            </handlers>
            <validation validateIntegratedModeConfiguration="false"/>
        </system.webServer>
    </location>
    <wwBanner>
        <add key="ConnectionString" value="server=.;database=WestwindAdmin;integrated security=true;"/>
        <add key="BannerManagerHandlerUrl" value="~/wwBanner.ashx"/>
        <add key="TrackStatistics" value="True"/>
        <add key="HomeUrl" value="~/admin/"/>
        <add key="wwBannerTable" value="wwBanners"/>
        <add key="wwBannerClicksTable" value="wwBannerClicks"/>
    </wwBanner>
    <appSettings>
        <add key="LogFile" value="c:\westwind\raslog\raslog.txt"/>
        <add key="AdminConnectionString" value="server=.;database=WestwindAdmin;integrated security=true;"/>
    </appSettings>    
</configuration>

The root site mappings basically handle all the non-virtual directories of the site so that I can have some ASP.NET functionality in the 'content' parts of my site. Things like link tracking, banner display and a few other maintenance applications run through these settings. The location tag as above guarantees that the root Web settings don't trigger down into the child virtuals which in the past has proved troublesome for some applications.

All this works great.

Except that Visual Studio doesn't correctly deal with this setup. Any change that is now made to web.config adds to the bottom of the config file rather than into the <location> specific tag. So adding a reference for example causes another <system.web> section to be added and ALL the references of the site now get readded there.

Not a big deal once you know but it took me a bit to figure out why all the sudden after adding a reference that the site would completely fail to run <s>.

It sure would be nice if VS could understand the Location tag, but I suspect this gets very difficult to parse. As it is the ASP.NET compiler complains about setting like Authentication in child Webs even though the authentication is hidden at the root (which was one of the main reasons that I needed to use the <location> tag.

On a side note - something has been screwed in my VS .NET 2008 setup in relation to editing the web.config file - whenever I press Ctrl-S to save the web.config document saves and CLOSES. Not sure WTF caused that behavior to crop up, nor do I have any idea on how to fix this <shrug>. Odd.

Posted in ASP.NET  Visual Studio  

The Voices of Reason


 

Roger Jennings
January 02, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

"On a side note - something has been screwed in my VS .NET 2008 setup in relation to editing the web.config file - whenever I press Ctrl-S to save the web.config document saves and CLOSES."

Same thing started happening to me about a week ago for no apparent reason.

--rj

Steve from Pleasant Hill
January 02, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

Were you guys at the same party? :)

Brian Lowry
January 02, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

My web.config has closing as well. Really irritating... have you found a fix, yet? Also, your text editor is giving me fits in Firefox.

-Brian

Velio
January 03, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

Same problem here - Ctrl+S, causes web.config closing.
I think this happend after I have installed ASP.NET 3.5 Extensions CTP and MVC Toolkit, but I'm not 100% sure about.

Regards,
Velio

Mike
January 03, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

Same here, web.config closes when I save it. I too have installed the ASP.NET 3.5 Extensions.

Rick Strahl
January 03, 2008

# re: Visual Studio and &lt;location&gt; parsing in web.config

I just got word from Omar Khan from Microsoft:

>> This is a known issue with the 3.5 Extensions CTP that is fixed in later builds. The issue specifically stems from the Entities designer, so if you have that installed you will see this behavior.

Looks like uninstalling hte ADO.NET entity designer will get the old behavior back.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024