Web.Sitemap Errors After .NET 4.0 / IIS7 Upgrade

I build much of my navigation by using the web.sitemap file. After upgrading my site to ASP.net 4.0 and IIS7, I’m seeing lots of errors related to the ‘Sitemap.CurrentNode’ property. Specifically, the CurrentNode is coming up null, when I know that the node exists in the web.sitemap file. Actually, trying to find any node in the web.sitemap file seems to be failing.

As an example, this page throws the exception, but you can see in web.sitemap file below that the node listed in the exception does in fact exist.

I am getting this error on what appears to be all pages which use the Sitemap.CurrentNode property on the web.sitemap file. Strangely, building my website sitemap using web.sitemap works just fine.

On my local machine using VS2010 everything works as expected.


<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    
	<siteMapNode url="~/default.aspx" title="Fantasy Football and Racing Cheat Sheets"  description="Create customized fantasy draft cheat sheets for various fantasy sports including NFL football and NASCAR racing, or free.">

    <siteMapNode url="~/register.aspx" title="Register"  description="Register to unlock the full power of CheatSheetWarRoom." />
    <siteMapNode url="~/sitemap.aspx" title="Sitemap" description="View all pages of our website provided as hyperlinks for easy navigation." />
		<siteMapNode url="~/faq.aspx" title="FAQ" description="Get answers to frequently asked questions." />
		<siteMapNode url="~/about.aspx" title="About" description="Read about what drove the creation of our cheat sheet creation tools." />
		<siteMapNode url="~/contact.aspx" title="Contact"  description="Contact us with any queries or suggestions you may have." />
		<siteMapNode url="~/passwordrecovery.aspx" title="Password Recovery"  description="If you've forgot your password, validate yourself and we'll sent it to you." />
		<siteMapNode url="~/editprofile.aspx" title="Edit Profile" description="Edit your personal profile to keep your personal information current." />
		<siteMapNode url="~/admin/Users/UserStats.aspx?" title="Admin" roles="Administrator" description="An entry point into the administration menu." />

    <!-- **************** -->
    <!-- Fantasy Football -->
    <!-- **************** -->

    <siteMapNode url="/FantasyFootball" title="Fantasy Football" description="These pages are relevant to fantasy football." roles="*" link="false">
      
      <!--Fantasy Football Landing Page-->
      <siteMapNode url="~/fantasy-football/nfl/cheat-sheets.aspx" title="Fantasy Football Cheat Sheets" description="Prepare for your 2010 NFL fantasy football draft by creating customized fantasy football cheat sheets, for free."></siteMapNode>
      <siteMapNode url="~/fantasy-football/nfl/cheat-sheet-help.aspx" title="Football Cheat Sheet Help" description="Explore all features for creating fantasy football cheat sheets."/>

      <!--Fantasy Football Cheat Sheet Creation-->
			<siteMapNode  url="/FantasyFootballCreateSheetCreation" title="Fantasy Football Cheat Sheet Creation" description="The creation of cheat sheets." roles="*" link="false">
				<siteMapNode url="~/fantasy-football/nfl/create/custom-sheet.aspx" title="Custom Fantasy Football Cheat Sheet" description="Use this free, custom fantasy football cheat sheet to easily create your NFL fantasy player rankings using drag and drop."></siteMapNode>
        <siteMapNode url="~/fantasy-football/nfl/create/editsheet.aspx" title="Edit Fantasy Football Cheat Sheet"></siteMapNode>
        <siteMapNode url="~/fantasy-football/nfl/create/newsheet.aspx" title="New Fantasy Football Cheat Sheet"></siteMapNode>
        <siteMapNode url="~/fantasy-football/nfl/create/managesheets.aspx" title="Manage Fantasy Football Cheat Sheet"></siteMapNode>
        <siteMapNode url="~/fantasy-football/nfl/create/configureprint.aspx" title="Configure Printable Fantasy Football Cheat Sheet" roles="Member, SupplementalSource, Administrator"></siteMapNode>
      </siteMapNode>  <!-- Close Fantasy Football Cheat Sheet Creation -->

      <!-- Fantasy Football Free -->
      <siteMapNode url="/FantasyFootballFree" title="Free Fantasy Football Resources" roles="*" link="false">


        <!-- Fantasy Football (Offensive) Player Rankings-->
        <siteMapNode url="~/fantasy-football/nfl/free/rankings/player-rankings.aspx" roles="*" title="2010 NFL Player Rankings">
          <siteMapNode url="/FantasyFootballFreeRankingsOffense" title="Offensive Positions" link="false"  roles="*">
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/quarterbacks.aspx" title="Quarterback Rankings" description="View our free quarterback rankings in preparation for your 2010 fantasy football draft." />
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/running-backs.aspx" title="Running Back Rankings" description="View our free running back rankings in preparation for your 2010 fantasy football draft." />
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/wide-receivers.aspx" title="Wide Receiver Rankings" description="View our free wide receiver rankings in preparation for your 2010 fantasy football draft." />
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/tight-ends.aspx" title="Tight End Rankings" description="View our free tight end rankings in preparation for your 2010 fantasy football draft." />
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/kickers.aspx" title="Kicker Rankings" description="View our free kicker rankings in preparation for your 2010 fantasy football draft." />
            <siteMapNode url="~/fantasy-football/nfl/free/rankings/offense/defenses.aspx" title="Defense Rankings" description="View our free defense rankings in preparation for your 2010 fantasy football draft." />
          </siteMapNode>
        </siteMapNode>  <!-- Close Fantasy Football Player Rankings -->

        <!-- Printable Fantasy Football Cheat Sheets-->
        <siteMapNode url="~/fantasy-football/nfl/free/printable/cheat-sheets.aspx" title="Printable Fantasy Football Cheat Sheets" roles="*">
          <siteMapNode url="/FantasyFootballFreePrintableCheatSheetsOffense" title="Offensive Positions" link="false"  roles="*">
            <!--All-in-One-->
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/cheat-sheet-with-roster.aspx" title="Printable Fantasy Football Cheat Sheet With Roster" roles="*"/>
            <!--By Position-->
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/quarterbacks-cheat-sheet.aspx" title="Printable Quarterbacks Cheat Sheet" roles="*"/>
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/running-backs-cheat-sheet.aspx" title="Printable Running Backs Cheat Sheet" roles="*"/>
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/wide-receivers-cheat-sheet.aspx" title="Printable Wide Receivers Cheat Sheet" roles="*"/>
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/tight-ends-cheat-sheet.aspx" title="Printable Tight Ends Cheat Sheet" roles="*"/>
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/kickers-cheat-sheet.aspx" title="Printable Kickers Cheat Sheet" roles="*"/>
            <siteMapNode url="~/fantasy-football/nfl/free/printable/offense/defenses-cheat-sheet.aspx" title="Printable Defenses Cheat Sheet" roles="*"/>
          </siteMapNode> <!-- Close Printable Fantasy Football Cheat Sheets OFFENSE -->
        </siteMapNode>  <!-- Close Printable Fantasy Football Cheat Sheets-->

        <!-- Fantasy Football Links -->
        <siteMapNode url="~/fantasy-football/nfl/free/links.aspx" title="Fantasy Football Links"  description="This page contains links to various fantasy NFL football websites categorized by type." />

      </siteMapNode>  <!-- Close Printable Fantasy Football Free -->

	  </siteMapNode>  <!-- Close Fantasy Football -->

    <!-- ************** -->
    <!-- Fantasy Racing -->
    <!-- ************** -->
    <siteMapNode url="/FantasyRacing" title="Fantasy Racing" description="These pages are relevant to fantasy racing." roles="*" link="false">

      <!-- Fantasy Racing Landing Page -->
      <siteMapNode url="~/fantasy-racing/nascar/cheat-sheets.aspx" title="Fantasy Racing Cheat Sheets" description="Prepare for your 2010 NASCAR fantasy racing draft by creating customized fantasy racing cheat sheets, for free."></siteMapNode>
      <siteMapNode url="~/fantasy-racing/nascar/cheat-sheet-help.aspx" title="Racing Cheat Sheet Help" description="Explore all features for creating fantasy racing cheat sheets."/>
      <!-- Fantasy Racing Cheat Sheet Creation -->
      <siteMapNode url="/FantasyRacingCreateSheetCreation" title="Fantasy Racing Cheat Sheet Creation" description="The creation of cheat sheets." roles="*" link="false">
        <siteMapNode url="~/fantasy-racing/nascar/create/custom-sheet.aspx" title="Custom Fantasy Racing Cheat Sheet" description="Use this free, custom fantasy racing cheat sheet to easily create your fantasy NASCAR driver rankings using drag and drop."></siteMapNode>
        <siteMapNode url="~/fantasy-racing/nascar/create/editsheet.aspx" title="Edit Fantasy Racing Cheat Sheet"></siteMapNode>
        <siteMapNode url="~/fantasy-racing/nascar/create/newsheet.aspx" title="New Fantasy Racing Cheat Sheet"></siteMapNode>
        <siteMapNode url="~/fantasy-racing/nascar/create/managesheets.aspx" title="Manage Fantasy Racing Cheat Sheet"></siteMapNode>
      </siteMapNode> <!-- Close Fantasy Racing Cheat Sheet Creation -->

      <!-- Fantasy Racing Free -->
      <siteMapNode url="/FantasyRacingFree" title="Free Fantasy Racing Resources" roles="*" link="false">
        <!-- Links -->
        <siteMapNode url="~/fantasy-racing/nascar/free/links.aspx" title="Fantasy Racing Links" description="This page contains links to various fantasy NASCAR racing websites categorized by type." />
        <!--Fantasy NASCAR Driver Rankings-->
        <siteMapNode url="~/fantasy-racing/nascar/free/rankings/drivers.aspx" title="2011 NASCAR Driver Rankings" description="Use this free, custom fantasy racing cheat sheet to easily create your fantasy NASCAR driver rankings using drag and drop." />
        <!--Free Fantasy NASCAR Cheat Sheets-->
        <siteMapNode url="~/fantasy-racing/nascar/free/printable/drivers-cheat-sheet.aspx" title="Free Printable Fantasy Racing Cheat Sheet" description="This free, printable fantasy racing cheat sheet includes all drivers for the 2010 fantasy NASCAR draft." />
      </siteMapNode> <!-- Close Fantasy Racing Free -->

    </siteMapNode>  <!-- Close Fantasy Racing -->


    <!-- Legal -->
    <siteMapNode title="Legal" roles="*">
			<siteMapNode url="~/Legal/Disclaimer.aspx" title="Disclaimer" description="Read our legal disclaimer to learn about who we are AND AREN'T affiliated with."/>
			<siteMapNode url="~/Legal/PrivacyPolicy.aspx" title="Privacy Policy" description="Your privacy is important to us and we won't share this information."/>
			<siteMapNode url="~/Legal/TermsOfService.aspx" title="Terms of Service" description="Our Terms of Service provide you with rules dictating how you can use our website."/>
		</siteMapNode>  <!--Close Legal-->

    
    <!--Administrative-->
    <siteMapNode url="/AdminMain" roles="Administrator" title="Admin" showNode="false">

      <siteMapNode url="~/admin/summary.aspx" roles="Administrator" title="Stats" description="">
        <!--Users-->
        <siteMapNode title="Users"  roles="Administrator" url="/Users" description="">
          <siteMapNode url="~/admin/users/manageusers.aspx" roles="Administrator" title="Manage Users"  description="" />
          <siteMapNode url="~/admin/users/edituser.aspx" roles="Administrator" title="Edit User"  description="" />
        </siteMapNode>
        <!--Football-->
        <siteMapNode title="Football" roles="Administrator" url="/Football" description="">
          <siteMapNode url="~/admin/sports/football/sheetsettings.aspx" roles="Administrator" title="Sheet Settings"  description="" />
          <!--Players-->
          <siteMapNode title="Players" roles="Administrator" url="/FootballPlayers" description="">
            <siteMapNode url="~/admin/sports/football/players/manageplayers.aspx" roles="Administrator" title="Manage Players"  description="" />
            <!--Stats-->
            <siteMapNode title="Stats" url="/FootballStats" roles="Administrator"  description="">
              <siteMapNode url="~/admin/sports/football/players/stats/manageplayerseasonstats.aspx" roles="Administrator" title="Manage Player Season Stats" description="" />
              <siteMapNode title="Import" roles="Administrator" description="">
                <siteMapNode url="~/admin/sports/football/players/stats/import/importseasonstats.aspx" roles="Administrator" title="Import Season Stats"  description="" />
                <siteMapNode url="~/admin/sports/football/players/stats/import/mapplayerids.aspx" roles="Administrator" title="Map PlayerIDs"  description="" />
              </siteMapNode>
            </siteMapNode>
          </siteMapNode>
          <!--Supplementals-->
          <siteMapNode title="Supplementals" roles="Administrator" url="/FootballSupplementals"  description="">
            <siteMapNode roles="Administrator" url="~/admin/sports/football/supplementals/managesupplementalsheets.aspx" title="Manage Supplemental Sheets"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/football/supplementals/editsupplementalsheet.aspx" title="Edit Supplemental Sheet"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/football/supplementals/ranksupplementalplayers.aspx" title="Rank Supplemental Players"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/football/supplementals/managesupplementalsources.aspx" title="Manage Supplemental Sources"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/football/supplementals/scraperankings.aspx" title="Scrape Rankings"  description="" />
          </siteMapNode>
        </siteMapNode>
        <!--Racing-->
        <siteMapNode title="Racing" roles="Administrator" url="/Racing" description="">
          <siteMapNode url="~/admin/sports/racing/sheetsettings.aspx" roles="Administrator" title="Sheet Settings"  description="" />
          <!--Drivers-->
          <siteMapNode title="Drivers" roles="Administrator" url="/RacingDrivers" description="">
            <siteMapNode url="~/admin/sports/racing/drivers/managedrivers.aspx" roles="Administrator" title="Manage Drivers"  description="" />
            <!--Stats-->
            <siteMapNode title="Stats" url="/RacingStats" roles="Administrator"  description="">
              <siteMapNode url="~/admin/sports/racing/drivers/stats/managedriverseasonstats.aspx" roles="Administrator" title="Manage Driver Season Stats" description="" />
            </siteMapNode>
          </siteMapNode>
          <!--Supplementals-->
          <siteMapNode title="Supplementals" roles="Administrator" url="/RacingSupplementals"  description="">
            <siteMapNode roles="Administrator" url="~/admin/sports/racing/supplementals/managesupplementalsheets.aspx" title="Manage Racing Supplemental Sheets"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/racing/supplementals/ranksupplementalplayers.aspx" title="Rank Supplemental Players"  description="" />
            <siteMapNode roles="Administrator" url="~/admin/sports/racing/supplementals/editsupplementalsheet.aspx" title="Edit Supplemental Sheet"  description="" />
          </siteMapNode>
        </siteMapNode>  
        <!--Health-->
        <siteMapNode title="Health" roles="Administrator" url="/Health" description="">
          <siteMapNode roles="Administrator"  url="~/admin/health/manageexceptions.aspx" title="Manage Exceptions"  description="" />
        </siteMapNode>
      </siteMapNode>
    

      </siteMapNode>

		<siteMapNode title="Errors">
		</siteMapNode>

	</siteMapNode>


</siteMap>


Step back to 3.5 (or whatever you were using) and see if you still have the problem – could be behaviour changes in several places, helps if you know which one.

That’s a good idea. After some further investigating, I think I’ve found the problem, but still not sure why its occurring. It seems the url of the SiteMapNodes are being mis-interpreted when the web.sitemap file is read. For instance, if I run the following code:


    SiteMapNode rootNode = SiteMap.Provider.RootNode;
    labTest.Text = rootNode.Url;

I would expect to see “~/default.aspx” from the above (as you can see in the code above this is the root node), but instead the following is read:

/(A(RAVFN-5DzAEkAAAANzE4MWZlMmUtYWI5OC00Nzg5LTk5YmMtNmEwNWRlNjAxYjU4KwIMaNwwBgRI9_M39CTzq6EZY7U1))/default.aspx

So, whenever I try to find a node in the web.sitemap based on url

SiteMapNode myNode = SiteMap.Provider.FindSiteMapNode(“/FantasyFootballFreeRankingsOffense”);

or bind to a SiteMapDataSource which has a ‘StartingNodeUrl’ property:

<asp:SiteMapDataSource ID=“dsMenu” runat=“server” ShowStartingNode=“false” EnableViewState=“false” StartingNodeUrl=“/FantasyFootballFreeRankingsOffense” />

it fails because of the jumbled text before the url which of course doesn’t match what I’m looking for. The only way I can get a match is to remove the ‘~/’ from the url in the web.sitemap file, but I don’t think that’s correct.

Preliminary indications are that it is an issue with <urlrewritingnet> which doesn’t seem to play well with ASP.net 4.0. I started noticing crawl errors in Google Webmaster Tools where the tilde was being replaced with garbled text, just like I was seeing in my queries against my sitemap. Turning off <urlrewritingnet> seems to have resolved the issue.

Yeah, really no point anymore – you’ve got integrated pipelines, routing and IIS-based URL rewriting.

Yeah but for shared hosting I still think I’m screwed. Oh well at least my valid pages are now being found.

I take it back, still broken and still hit-and-miss.

http://www.cheatsheetwarroom.com/test/testnodes.aspx

/(X(1)A(2gOVYYFGzAEkAAAANGFhMzNjMmEtNWE3ZC00YzBhLThiZTAtMjc5NDU2MmI2OGU2KnIaxY49M-0oPCwVg0mZwM_HTLo1))/default.aspx

I’m now able to prove that editing the web.config temporarily fixes the problem. So somehow recycling the app domain causes the problem to vanish for some time.

Edit:

Took your advice and reverted back to ASP.net 3.5 (still under IIS7) and everything is back to working 100%. Any ideas going forward?

IIS7 url rewriting is configured in the same place as the old one, it is meant to work on shared hosting.

That funny url is because the runtime couldn’t set the session cookies so it fell back on putting your session ID in the URL.

Not exactly sure what is going on here in any case, but I’ve never relied upon the default implementation of IsCurrentNode as it never fit our requirements.

Those funny urls have also been filling my crawl error logs. It’s as though that runtime is substituting the session ID for the ‘~’ character when building my links:

http://www.cheatsheetwarroom.com/(A(Vorh1IhBzAEkAAAAYmRjNzlkOTgtYTc0Yi00NDNiLWE1NWMtODI0MzY1Mzk4MDJkWZMS4s9nKNqrID67-zn2KFX_NB41))/Fantasy-Football/nfl/create/custom-sheet.aspx.cs

Any idea why the runtime wouldn’t be able to set session cookies? I can still log into my site and establish sessions, so cookies must be working in some form or fashion. It’s only when I query against the web.sitemap file (or when rewriting urls using <urlrewritingnet> that I get those strange urls.

Not exactly sure what is going on here in any case, but I’ve never relied upon the default implementation of IsCurrentNode as it never fit our requirements.

Logic would tell me that the funny urls in my crawl error logs and the funny urls that I’m reading from web.sitemap file are one and the same issue. I have also just discovered that yesterday after removing the <urlrewritingnet> rules from my web.config my crawl errors ceased.

So, my thinking was that <urlrewritingnet> must have also been the cause of reading the funny urls from my web.sitemap file. But low and behold I’m still seeing the funny urls when querying against web.sitemap.

Probably browsers that don’t accept cookies, like search engine crawlers. I would actually disable the behavior myself. Not exactly sure what the setting is offhand but it should be fairly obvious.

I’m not sure which behavior you’re talking about? Disabling cookies?

Sorry, disabling the “if browser does not take cookies, start a session and stuff the session ID into the URL” behavior.

I’m not so sure we’re dealing with the SessionID. The default value for ‘cookieless’ in the web.config is ‘false’ and I’m not setting this variable so I’m pretty sure it’s turned off. In addition, the SessionID is normally inserted right before the resource being requested, but the strange string I’m seeing is always right after the domain name:

http: //www. cheatsheetwarroom.com/(A(haYLYUOXywEkAAAAZjk1ZDljZWQtNzE5Yy00OThmLWJmZjAtMzk4YjVkZWNiYTI4DJDXTINND96Q2punOfRVChL-Nx01))/fantasy-football/nfl-2009/wide-receiver-rankings.aspx?Page=5&Position=WR

I still think that the ASP.net engine is somehow mis-interpreting the ‘~’ character when building absolute links based on a relative link containing the ‘~’ character.

That article is 6 years old now, before we had URL routing so things might have changed. Profiles could be another source, but it is definitely a system-generated unique ID for something.

You could be right there anyhow, have you tried to reproduce the behavior directly and cleanly without sitemaps and such?

I can’t reproduce the behavior at all on my local machine, but I’m developing with the built-in server of VS2010. The only place I’m seeing the problem is on my web host, but I haven’t tried to host my application locally on my dev machine with true IIS so I guess that should be my next step.

I’m not really sure how to produce the problem without using the sitemap since that seems to be the only place where the problem is appearing.