Sitemap randomly breaks over time
Asked Answered
W

3

11

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 (shudders - yes, I know - we're porting it to MVC but that's taking some time).

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.

The error: Could not find the sitemap node with URL '~/Default.aspx'.

A simplified version of our sitemap (with some names changed and uninteresting nodes removed) is as follows:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
   <siteMapNode roles="*" title="EG">
      <siteMapNode url="~/../SM/Default.aspx" title="Welcome" description="" roles="*" />
      <siteMapNode url="~/../SD/Default.aspx" title="SD" description="" roles="*" />
      <siteMapNode url="~/../SMD/Default.aspx" title="SMD" description="" roles="*" />
      <siteMapNode url="~/Default.aspx" title="Ops" description="" roles="*" >
         <siteMapNode url="~/Error.aspx" title="Error" hide="true" roles="*" />
         <siteMapNode url="~/Public/Login.aspx" hide="true" roles="*" />
         <siteMapNode url="~/Manager/LPCE.aspx" title="LPCE" description="" roles="Administrator, Manager, System, Marketer" imageUrl="~/../SM/images/icons/LF.jpg" />
      </siteMapNode>
      <siteMapNode url="~/../SDD/Default.aspx" title="SDD" description="" roles="*" />
      <siteMapNode url="~/../CCD/Default.aspx" title="CCD" description="" roles="*" />
      <siteMapNode url="~/../RD/Default.aspx" title="RD" description="" roles="*"/>
      <siteMapNode url="~/../SBD/Default.aspx" title="SBD" description="" roles="*" />
   </siteMapNode>
</siteMap>

It is registered in our web.config:

<siteMap defaultProvider="SDXmlSiteMapProvider" enabled="true">
  <providers>
    <add name="SDXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true" />
    <add name="SecurityDisabledSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="false" />
  </providers>
</siteMap>

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:

private void Page_Load(object sender, EventArgs e)
{
   if(!IsPostBack)
   {
        SiteMapDataSource.StartingNodeUrl = "~/Default.aspx";
   }
}

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.

The problems I have considered:

  1. SiteMap does not have a node for Default.aspx. All of them do.
  2. SiteMap's Default.aspx node is not accessible for security reasons to the current user/role. They're all accessible to anonymous users and this problem even exists for super admin users.
  3. Passed-in URL contains querystrings (Default.aspx?abcd). 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.
  4. SiteMap changes. It doesn't
  5. Service's permissions to the sitemap file. 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.
  6. The worker process becomes globally corrupt. 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.

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 IISRESET or equivalent. And even then, there's no telling as to how long the problem will be resolved. This is VERY frustrating!

Windfall answered 2/8, 2010 at 17:37 Comment(6)
What server is this hosted on?Locust
We are STILL having this problem and would STILL like to have an answer for this...Windfall
Few weird things in your code I don't understand. ~ is the website root : why ~/../ ? Do you work with separate IIS websites ? private void Page_Load on a base page : private and not protected (event is fired?) ? Page_Load on base page instead of OnLoad ? It seems to be a website context error : your IIS production environment may differs ?Fireboard
if you have upgraded to .net 4, why are the types of XmlSiteMapProvider still pointing to version 2? A stack trace would also be nice to see, and you should consider adding some code to dump the content of the XmlSiteMapProvider-instance when the error occurs.Cyclo
>>(shudders - yes, I know - we're porting it to MVC but that's taking some time).. Take a deep breath. You'll still have bugs in MVCGarnett
I never answered the above questions. For why ~/../, we have multiple web apps that are "integrated" via URL navigation in our menu, and our menu is driven by the sitemap. Clearly we have more than 3 pages in each app so the above sitemap is simplified a bit, but that's why we have the ~/../ paths. Yes, Page_Load is fired (we have other stuff in there too). For XmlSiteMapProvider, this is what Msft has for .NET 4: msdn.microsoft.com/en-us/library/…Windfall
K
2

I put a previous post on this thread that got deleted :( anyhow I 'had' the same problem.

I found that no matter what I did the "Could not find the sitemap node with URL '~/rootnode" occurred. My break came when I decided to remove the file system dependency and switch to the SqlSiteMapProvider from wicked code. I found that this problem was more reliably re-created.

In short you get that message because there is no site map! I found that on the site map data source if you use the StartingNodeUrl="~/root.htm" then the error message will appear when there is no sitemap built. However if you use StartingNodeOffset="0" then the error message is not displayed and there simply is no menu rendered when the sitemap is not built.

Seemed strange to me but I traced it back to the XmlSiteMapProvider. Sometimes it built sometimes it didn't. Couldn't get my head fully under the bonnet but it looked like something happening Asynchronously. Anyhow I've switched to the SqlSiteMapProvider from wickedcode.

One change I made, aside from converting to vb was to put a recursive call on the return of the overridden BuildSiteMap method:

' Return the root SiteMapNode
If _Root Is Nothing Then
   Return Me.BuildSiteMap
Else
   Return _Root
End If

This makes sure the sitemap builds. I thought about putting an infinite recursion guard in but it doesn't seem to be required.

I'm still thinking that perhaps a network lag or some authentication (which at our place is through an AD controller, and lags first thing in the morning !!) is what is making the XmlSiteMapProvider miss it's Async build window?

Really hope this helps.

Kickback answered 27/9, 2012 at 9:8 Comment(0)
Y
0

Hmm. Its been a couple of years since I worked with ASP.net, but if I recall, I had a similar problem which I solved with

Page.ResolveURL("~SomePage.aspx");

At runtime the sitemap urls are resolved to the actual url, so the tilde is removed and replaced with the actual URL (I think :) ).

Yearning answered 29/11, 2010 at 10:6 Comment(2)
So have you solved it yourself yet? OIf so, other people may be interested in know how. Like I said, its been a while.Yearning
Nope, the least-intrusive band-aid solution that I have found and use today is to have an automated service email me whenever it goes down and I perform a trivial edit to the web.config to force the app to recompile (like adding a space). Still no real solution.Windfall
B
0

I have two possible ideas for this problem. Neither is guaranteed to work. ;-)

  1. Is it possible that you are also using URL Authorization at the same time in some of your web.config files located in various folders throughout your web application?

    Example URL Authorization setting that could be found in one web.config file:

    <location path="bobsSecret.aspx"> 
        <system.webServer> 
            <security> 
                <authorization> 
                    <remove users="" roles="BobAndFriends" verbs="" /> 
                    <add accessType="Allow" users="Bob" />          
    
                </authorization> 
            </security> 
        </system.webServer> 
    </location> 
    

    The reason I mention this is I had some trouble in the past trying to get the roles property in my sitemap XML file to work correctly with the settings I had applied in my URL Authorization in a web.config.

    The only thing I could imagine would be some sort of race condition where the process responsible for enforcing these policies is reading one security setting in one place (web.config) before reading it in another place (web.sitemap).

    Just a stab in the dark, based off some past issues I had experienced!

  2. As a second option, you could consider putting this configuration in your aspx page instead of in the Page_Load event on the code behind. You could try this:

    <asp:SiteMapDataSource
        id="SiteMapDataSource1"
        runat="server"
        StartingNodeUrl="~/Default.aspx">
    </asp:SiteMapDataSource>
    

    This way your StartingNodeUrl is specified in the ASPX page itself, and if this is truly an intermittent bug in the Framework code, perhaps this slight change might fix the problem.

Blarney answered 15/9, 2011 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.