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")
)
);
}
}
Old version Sitemap @ 4pmdesign
最新推荐文章于 2019-09-05 20:16:53 发布