Old version Sitemap @ 4pmdesign

 public ContentResult Sitemap()
        {
            //Code to generate a random double to add it to the lastmode node and rest it from datetime.now to show always a different time of modification
            //being this always less than datetime.now to make it trustable
            int n = new Random().Next(1, 9);
            Random r = new Random();
            double ra = r.NextDouble();
            string rS = ra.ToString();
            string nS = n.ToString();
            string[] Arr = rS.Split('.');
            string ReducedS = Arr[1].Substring(0, 3);
            string DoubleS = nS + "." + ReducedS;
            double D = Convert.ToDouble(DoubleS);
            DateTime ed = DateTime.Now.AddHours(-D);
            
            //XElement Tree = new XElement("content");
            //XNamespace xn = "http://www.google.com/schemas/sitemap/0.84";
            //foreach (var item in Cache.Tags.Where(c => c.Type == DAL.fouradman.Tag.Types.type))
            //{

            //    Tree.Add(new XElement("Templates",
            //        new XElement("url", "http://4pmdesign.com" + Url.Action("Index", "Template", new { type = item.Value("en"), })),
            //        new XElement("title", string.Format("Templates of {0}", item.Value("en"))),
            //        new XElement("priority", "0.5"),
            //        new XElement("lastmod", ed.ToShortTimeString()),
            //        new XElement("changefreq", "Daily")
            //        )
            //        );
            //    //foreach (var Ta in Cache.Tags.Where(c => c.Type == DAL.fouradman.Tag.Types.type))
            //    //{
            //    //    Tree.Add(new XElement("tag", Ta.Tags));

            //    //}

            //}

            //XDocument xd = new XDocument(
            //new XDeclaration("1.0", "utf-8", "yes"),
            //new XElement(xn + "urlset").FirstAttribute,
            //new XElement(Tree));


            //return this.Content(xd.ToString(), "text/xml");


 //#####################################################################################################################################
 //#########################################  For Display every Template  ############################################################################

            XNamespace xn1 = "http://www.google.com/schemas/sitemap/0.84";
            XElement UrlTree = new XElement(xn1 + "urlset");
            

            using (var dc = new DAL.fouradman.fouradmanDataContext())
            {
                var counter = dc.Templates.OrderByDescending(c => c.Id).ToList();

                foreach (var t in counter)
                {
                    var taglist = dc.Template_Tags.Where(c => c.Template_Id.Equals(t.Id)).ToList();

                    foreach (var d in taglist)
                    {
                        d.Tag.Translation = (String)dc.Tags.Where(c => c.Id.Equals(d.Tag_Id)).Select(c => c.Translation).FirstOrDefault().ToString();
                    }

                    System.Text.StringBuilder tagsstring = new System.Text.StringBuilder();
                    foreach (var d in taglist)
                    {
                        tagsstring.AppendLine(d.Tag.Translation);
                    }
                    tagsstring.Replace('&', '-');
                    tagsstring.Replace(' ', '-');
                    //tagsstring.Replace(':', '-');
                    tagsstring.Replace("&", "");
                    tagsstring.Replace(" ", "");
                    //tagsstring.Replace(":", "");
                    tagsstring.Replace((char)13, '-');
                    tagsstring.Replace((char)10, '-');
                    tagsstring.Replace("en:", "");


                    UrlTree.Add(new XElement("url",
                    new XElement("loc", "http://4pmdesign.com" + Url.Action("SEOpage", "Template", new { templateId = t.Id, keywords = tagsstring.ToString() })),                                    
                    new XElement("lastmod", ed.ToShortTimeString()),
                    new XElement("changefreq", "Daily"),
                    new XElement("priority", "0.5")
                    )
                    );

                }
            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值