ASP.NET生成Google網(wǎng)站地圖的代碼
更新時(shí)間:2009年08月16日 13:10:39 作者:
生成google網(wǎng)站地圖的實(shí)現(xiàn)代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
/// <summary>
/// 生成google網(wǎng)站地圖
/// </summary>
/// <returns></returns>
public static boolBuildGoogleSitemap()
{
try
{
string RootDirectory = AppDomain.CurrentDomain.BaseDirectory;
XmlTextWriter Writer = new XmlTextWriter(HttpContext.Current.Server.MapPath("~/GoogleSitemaps.xml"), Encoding.GetEncoding("utf-8"));
Writer.Formatting = Formatting.Indented;
Writer.WriteStartDocument();
Writer.WriteStartElement("urlset", "http://www.google.com/schemas/sitemap/0.84");
//遍歷掃描網(wǎng)站所有文件
showfiles(RootDirectory, Writer);
Writer.WriteEndElement();
Writer.WriteEndDocument();
Writer.Close();
return true;
}
catch (Exception err)
{
return false;
}
}
//遍歷掃描網(wǎng)站所有文件
static void showfiles(string dirpath, XmlTextWriter Writer)
{
bool IsRead = true;
string[] NotRead ={ "App_Data", "Bin", "fckeditor", "js", "MyAdmin", "PowerChatRoom" };//排除這些文件夾
foreach (string s in NotRead)
{
string dirname = dirpath.Substring(dirpath.LastIndexOf(@"\") + 1);
if (dirname == s)
{
IsRead = false;
break;
}
}
if (!IsRead)
return;
try
{
DirectoryInfo dir = new DirectoryInfo(dirpath);
foreach (FileInfo f in dir.GetFiles())
{
string path = dir.FullName.Replace(AppDomain.CurrentDomain.BaseDirectory, "");//文件相對(duì)目錄
//HttpContext.Current.Response.Write(AppDomain.CurrentDomain.BaseDirectory + "**********" + dir.FullName + "<br>");
Writer.WriteStartElement("url");
Writer.WriteStartElement("loc");
StringBuilder sb = new StringBuilder("/" + path + "/" + f.Name);
sb.Replace("http://", "/").Replace(@"\", "/");
Writer.WriteString(ConfigurationManager.AppSettings["WebSiteUrl"].ToString() + sb.ToString());
Writer.WriteEndElement();
Writer.WriteStartElement("lastmod");
Writer.WriteString(string.Format("{0:yyyy-MM-dd}", f.LastWriteTime));
Writer.WriteEndElement();
Writer.WriteStartElement("changefreq");
Writer.WriteString("always");//更新頻率:always:經(jīng)常,hourly:小時(shí),daily:天,weekly:周,monthly:月,yearly:年
Writer.WriteEndElement();
Writer.WriteStartElement("priority");
Writer.WriteString("0.8");//相對(duì)于其他頁(yè)面的優(yōu)先權(quán),此值定于0.0 - 1.0之間
Writer.WriteEndElement();
Writer.WriteEndElement();
}
foreach (DirectoryInfo d in dir.GetDirectories())
{
showfiles(d.FullName, Writer);
}
}
catch (Exception) { }
}
相關(guān)文章
Asp.Net 網(wǎng)站性能優(yōu)化之緩字決 (上) 緩沖寫數(shù)據(jù)
通常情況下Asp.Net 網(wǎng)站的底層數(shù)據(jù)存儲(chǔ)都是關(guān)系數(shù)據(jù)庫(kù),關(guān)系數(shù)據(jù)庫(kù)資源比較昂貴,而且也很容易造成瓶頸。緩字決文章就是為大家介紹如何有效使用緩存,異步寫緩沖數(shù)據(jù)庫(kù)的壓力,從而保證網(wǎng)站的性能。2010-06-06asp.net 因?yàn)閿?shù)據(jù)庫(kù)正在使用的解決方法
因?yàn)閿?shù)據(jù)庫(kù)正在使用,所以未能獲得對(duì)數(shù)據(jù)庫(kù)的排它訪問(wèn)權(quán)?2009-02-02.net MVC使用Session驗(yàn)證用戶登錄(4)
這篇文章主要為大家詳細(xì)介紹了.net MVC使用Session驗(yàn)證用戶登錄的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04asp.net Cookie值中文亂碼問(wèn)題解決方法
cookie里面不能寫中文,是由于cookie先天的編碼方式造成的,所以有必要存在一種中間的編碼方式:URLEncode是最好的選擇,感興趣的你可千萬(wàn)不要錯(cuò)過(guò)了哈,或許本文提供的知識(shí)點(diǎn)對(duì)你學(xué)習(xí)cookie有所幫助2013-02-02