title: Sitemap randomly breaks over time
body: <p>I've been having some production runtime errors that I don't fully understand. This has happened to us on a couple different ASP.NET 4.0 Web Sites (<em>shudders</em> - yes, I know - we're porting it to MVC but that's taking some time).</p>
  
  <p>First of all, we have never been able to reproduce this issue in development/QA environments. Secondly, upon deployment, the issue seems to be non-existent. Sometimes the issue manifests within a day or two of deployment and other times the deployment will be live for a month without it manifesting at all. However, once it manifests, then ANY page viewed under the web site causes the error. Lastly, this problem seemed to only come up once we migrated to .NET 4.0. We started at 2.0, a year ago upped to 3.5, and recently upped to 4.0 with this solution and most child projects.</p>
  
  <p>The error:
  <code>Could not find the sitemap node with URL '~/Default.aspx'.</code></p>
  
  <p>A simplified version of our sitemap (with some names changed and uninteresting nodes removed) is as follows:</p>
  
  <pre><code>&lt;siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"&gt;
     &lt;siteMapNode roles="*" title="EG"&gt;
        &lt;siteMapNode url="~/../SM/Default.aspx" title="Welcome" description="" roles="*" /&gt;
        &lt;siteMapNode url="~/../SD/Default.aspx" title="SD" description="" roles="*" /&gt;
        &lt;siteMapNode url="~/../SMD/Default.aspx" title="SMD" description="" roles="*" /&gt;
        &lt;siteMapNode url="~/Default.aspx" title="Ops" description="" roles="*" &gt;
           &lt;siteMapNode url="~/Error.aspx" title="Error" hide="true" roles="*" /&gt;
           &lt;siteMapNode url="~/Public/Login.aspx" hide="true" roles="*" /&gt;
           &lt;siteMapNode url="~/Manager/LPCE.aspx" title="LPCE" description="" roles="Administrator, Manager, System, Marketer" imageUrl="~/../SM/images/icons/LF.jpg" /&gt;
        &lt;/siteMapNode&gt;
        &lt;siteMapNode url="~/../SDD/Default.aspx" title="SDD" description="" roles="*" /&gt;
        &lt;siteMapNode url="~/../CCD/Default.aspx" title="CCD" description="" roles="*" /&gt;
        &lt;siteMapNode url="~/../RD/Default.aspx" title="RD" description="" roles="*"/&gt;
        &lt;siteMapNode url="~/../SBD/Default.aspx" title="SBD" description="" roles="*" /&gt;
     &lt;/siteMapNode&gt;
  &lt;/siteMap&gt;
  </code></pre>
  
  <p>It is registered in our web.config:</p>
  
  <pre><code>&lt;siteMap defaultProvider="SDXmlSiteMapProvider" enabled="true"&gt;
    &lt;providers&gt;
      &lt;add name="SDXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true" /&gt;
      &lt;add name="SecurityDisabledSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="false" /&gt;
    &lt;/providers&gt;
  &lt;/siteMap&gt;
  </code></pre>
  
  <p>And from logs I have narrowed down what causes the error is in a base class that pretty much all of our pages derive from:</p>
  
  <pre><code>private void Page_Load(object sender, EventArgs e)
  {
     if(!IsPostBack)
     {
          SiteMapDataSource.StartingNodeUrl = "~/Default.aspx";
     }
  }
  </code></pre>
  
  <p>I have confirmed in all of the SiteMaps that there is a node with url="~/Default.aspx" with roles="*" (which includes public/anonymous access), so I am very confused as to why this problem occurs.</p>
  
  <p>The problems I have considered:</p>
  
  <ol>
  <li>SiteMap does not have a node for Default.aspx. <strong><em>All of them do.</em></strong></li>
  <li>SiteMap's Default.aspx node is not accessible for security reasons to the current user/role. <strong><em>They're all accessible to anonymous users and this problem even exists for super admin users.</em></strong></li>
  <li>Passed-in URL contains querystrings (Default.aspx?abcd). <strong><em>I don't know if this is a problem (I sure would hope not) but once the problem manifests itself, I can handwrite the URL with no querystrings and the problem still exists.</em></strong></li>
  <li>SiteMap changes. <strong><em>It doesn't</em></strong></li>
  <li>Service's permissions to the sitemap file. <strong><em>The sitemap works perfectly fine after a deployment, so unless permissions are changed in a way that IISRESET fixes, then this is not an issue.</em></strong></li>
  <li>The worker process becomes globally corrupt. <strong><em>I don't think so. We have ~12 web sites all in the same app pool and the problem always stays confined within a single web site. Also, we have yet to have this happen to more than a single web site at a time although it has manifested itself in 4 different ones so far.</em></strong></li>
  </ol>
  
  <p>Can anybody shed some light on this? It almost seems as though the dynamically-compiled SiteMap gets corrupted or something. The only resolution I have found is an <code>IISRESET</code> or equivalent. And even then, there's no telling as to how long the problem will be resolved. This is VERY frustrating!</p>