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:
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With