Пример #1
0
        public ActionResult CreateSiteMap(HttpContextBase httpContext, IEnumerable <SiteMapIndexNodeModel> nodes)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            string baseUrl = baseUrlProvider.GetBaseUrl(httpContext);

            List <SiteMapIndexNodeModel> nodeList = nodes != null?nodes.ToList() : new List <SiteMapIndexNodeModel>();

            nodeList.ForEach(node => ValidateUrl(baseUrl, node));

            var sitemap = new SiteMapIndexModel(nodeList);

            return(actionResultFactory.CreateXmlResult(sitemap));
        }
 private string GetSitemapIndexXMLString()
 {
     using (StringWriter str = new Utf8StringWriter())
         using (XmlWriter writer = XmlWriter.Create(str))
         {
             XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
             ns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9");
             XmlSerializer xser = new XmlSerializer(typeof(SiteMapIndexModel));
             var           obj  = new SiteMapIndexModel
             {
                 SiteMapIndexUrls =
                 {
                     new SiteMapIndexNodeModel {
                         Url = "userpages.xml"
                     },
                     new SiteMapIndexNodeModel {
                         Url = "testpage.xml"
                     }
                 }
             };
             xser.Serialize(writer, obj, ns);
             return(str.ToString());
         }
 }