Duplicate Application Path appears in generated Urls

Aug 8, 2010 at 8:25 PM

Hi!

I just started to use MVC SiteMap Provider and running into an issue. Here is the generated sitemap.xml:

<?xml version="1.0" encoding="utf-8" ?>
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
      <loc>http://localhost/CGWeb//CGWeb/</loc>
      <lastmod>2010-08-08T08:00:00</lastmod>
      <changefreq>always</changefreq>
      <priority>0.5</priority>
    </url>
    <url>
      <loc>http://localhost/CGWeb//CGWeb/area1/Home</loc>
    </url>
    <url>
      <loc>http://localhost/CGWeb//CGWeb/area2/Home</loc>
    </url>
  </urlset>

The sitemap itself is simple also:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="false">
  <mvcSiteMapNode title="xxx" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal" lastModifiedDate="2010-08-08T08:00:00">
    <mvcSiteMapNode title="yyy" area="area1" controller="Home" action="Index" />
    <mvcSiteMapNode title="zzz" area="area2" controller="Home" action="Index" />
  </mvcSiteMapNode>
</mvcSiteMap>
I've configured the asp.net mvc application in IIS7 as an application.
 
I also located the root of the problem. The MVC URL Action Resolver will resolve the action Urls to this for the default Home Index action: /CGWeb/
After this all url will contains the server relative urls and not the app relative urls!
 
Later within UrlUtilities.ResolveServerUrl you're resolving the "~/" path to: http://localhost/CGWeb which leads to the error since in XmlSiteMapResult.GenerateUrlElements you've this code:
                var urlElement = new XElement(Ns + "url",
                    new XElement(Ns + "loc", url + siteMapNode.Url));
Which just concatenates the resolver server url + the action url => http://localhost/CGWeb + /CGWeb/ and it will appear in the xml sitemap.
What can you suggest to make it work? Using the Uri.GetLeftPart (UriPartial.Authority) can help us here since that will resolve to http://localhost but I'm sure you made more tests then me, specially in cloud areas...I don't know how will that affect it.
Looking forward for your fix, meanwhile I'll register the route by hand and I'll pass in another base url for the constructor by hand.
Thanks,
Attila
Coordinator
Aug 9, 2010 at 8:35 AM

Can you post me the route table?

Aug 9, 2010 at 9:30 AM

How can I dump that to a human readable form? Or you need my RegisterRoute code snippets only?

Aug 9, 2010 at 9:41 AM

I've configured route debugger, here is the output: 

All Routes
Matches Current Request Url Defaults Constraints DataTokens
False area1/{controller}/{action}/{id} action = Index, id = System.Web.Mvc.UrlParameter (null) Namespaces = System.String[], area = area1, UseNamespaceFallback = False
False area2/{controller}/{action}/{id} action = Index, id = System.Web.Mvc.UrlParameter (null) Namespaces = System.String[], area = area2, UseNamespaceFallback = False
False {resource}.axd/{*pathInfo} (null) (null) (null)
False sitemap.xml controller = Home, action = XmlSiteMap (null) Namespaces = System.String[]
True {controller}/{action} controller = Home, action = Index (null) Namespaces = System.String[]
True {*catchall} (null) (null) (null)

 

 

Coordinator
Aug 10, 2010 at 6:35 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.