2012-07-13 69 views

回答

1

你可以在你的默認路由之前註冊的路線:

routes.MapRoute(
    "Sitemap", 
    "sitemap.xml", 
    new { controller = "Sitemap", action = "Index" } 
); 

,然後你可以有一個SitemapController

public class SitemapController: Controller 
{ 
    public ActionResult Index() 
    { 
     var model = ... 

     // Don't look for XmlResult, it's up to you to write it 
     return new XmlResult(model); 
    } 
} 

現在,當你瀏覽到/sitemap.xml,該Sitemap控制器的Index行動將被執行。

+1

我想你應該提到這條新路線應該高於默認路線。因爲訂單很重要 – Shyju 2012-07-13 17:42:37

+1

是的,這是正確的。我已更新提及它。 – 2012-07-13 17:43:21

+0

聽起來不錯,非常感謝。 – larryq 2012-07-13 17:45:25