コード例 #1
0
        public async Task <ActionResult> SitemapIndex()
        {
            // Get projects
            int pageCount = await _projectService.GetSitemapPageCountAsync();

            // Build sitemap index
            var sitemapIndex = new SitemapIndexModel();

            for (int i = 0; i < pageCount; ++i)
            {
                sitemapIndex.Sitemaps.Add(new SitemapIndexItem
                {
                    Location = Url.RouteUrl(RouteNames.Sitemap, new { page = i }, Request.Url != null ? Request.Url.Scheme : "http")
                });
            }

            // Serialize
            var serializer = new XmlSerializer(typeof(SitemapIndexModel));

            var xmlns = new XmlSerializerNamespaces();

            xmlns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9");

            var xmlStream = new MemoryStream();

            serializer.Serialize(xmlStream, sitemapIndex, xmlns);
            xmlStream.Seek(0, SeekOrigin.Begin);

            return(File(xmlStream, "text/xml"));
        }
コード例 #2
0
        public void CreateSitemapIndex_CreatesSitemapIndexXmlResult()
        {
            List<SitemapIndexNode> indexNodes = new List<SitemapIndexNode> { new SitemapIndexNode("/relative") };
            SitemapIndexModel sitemapIndexModel = new SitemapIndexModel(indexNodes);

            var result = sitemapProvider.CreateSitemapIndex(sitemapIndexModel);

            result.Should().BeOfType<XmlResult<SitemapIndexModel>>();
        }
コード例 #3
0
        public void CreateSitemapIndex_CreatesSitemapIndexXmlResult()
        {
            List <SitemapIndexNode> indexNodes = new List <SitemapIndexNode> {
                new SitemapIndexNode("/relative")
            };
            SitemapIndexModel sitemapIndexModel = new SitemapIndexModel(indexNodes);

            var result = sitemapProvider.CreateSitemapIndex(sitemapIndexModel);

            result.Should().BeOfType <XmlResult <SitemapIndexModel> >();
        }
コード例 #4
0
        public void Serialize_SitemapIndexModel()
        {
            SitemapIndexModel sitemapIndex = new SitemapIndexModel(new List<SitemapIndexNode>
            {
                new SitemapIndexNode { Url = "abc" },
                new SitemapIndexNode { Url = "def" }
            });

            string result = _serializer.Serialize(sitemapIndex);

            result.Should().BeXmlEquivalent("Samples/sitemap-index.xml");
        }
コード例 #5
0
        public void Serialize_SitemapIndexModel()
        {
            SitemapIndexModel sitemapIndex = new SitemapIndexModel(new List <SitemapIndexNode>
            {
                new SitemapIndexNode {
                    Url = "abc"
                },
                new SitemapIndexNode {
                    Url = "def"
                }
            });

            string result = serializer.Serialize(sitemapIndex);

            result.Should().BeXmlEquivalent("sitemap-index.xml");
        }