時(shí)間:2023-07-08 06:15:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-07-08 06:15:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)
Pageadmin 系統(tǒng)創(chuàng)建站點(diǎn)地圖sitemap.xml的方法:最近使用了Pageadmin這個(gè)建站系統(tǒng)建了一個(gè)簡(jiǎn)單的網(wǎng)站。為什么沒(méi)有使用PHP+MySQL,是因?yàn)樵瓉?lái)這個(gè)云主機(jī)已經(jīng)有了一個(gè)IIS+SQL組合的網(wǎng)站了,為了統(tǒng)一,所以找了支持這個(gè)平臺(tái)的Pageadmin來(lái)建站。Pageadmin系統(tǒng)的使用可以說(shuō)好,也可以說(shuō)不好。一言難盡。@{ Layout = null; string table = Request.QueryString["table"]; string domain = "http://localhost:800/buildSiteMap.cshtml";//localhost:800改為您的網(wǎng)站域名,必須是外網(wǎng)域名 //生成欄目siteMap if (table=="column") { <!--?xml version="1.0" encoding="utf-8" ?--> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/"> @foreach (var item in Html.GetColumnList().Where(c => c.Show == 1 && c.ColumnType <= 2)) { string url = Html.ColumnUrl((int)(item.Id)); <url> <mobile:mobile type="pc,mobile"> <loc>@url</loc> <lastmod>@DateTime.Now.ToString("yyyy-MM-dd")</lastmod> <changefreq>weekly</changefreq> <priority>0.8</priority> </mobile:mobile></url> } </urlset> } //生成信息表的siteMap else if (!string.IsNullOrEmpty(table)) { <!--?xml version="1.0" encoding="utf-8" ?--> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> @foreach (var item in Html.InfoDataList(new { Table = table, ShowNumber = 1500 })) { <url> <mobile:mobile type="pc,mobile"> <loc>http://www.pageadmin.net/jianzhan/@(item.Id).cshtml</loc> <lastmod>@item.Thedate.ToString("yyyy-MM-dd")</lastmod> <changefreq>weekly</changefreq> <priority>0.5</priority> </mobile:mobile></url> } } </urlset> } else { HttpRequestHelper httpRequestHelper = new HttpRequestHelper(); //生成欄目siteMap文件 IOHelper.CreateFile("/columnSiteMap.xml", httpRequestHelper.Get(domain+"?table=column").Trim(), true); //生成product表的siteMap文件,必須保證news信息表實(shí)際存在 IOHelper.CreateFile("/productSiteMap.xml", httpRequestHelper.Get(domain+"?table=product").Trim(), true); //生成news表的siteMap文件,必須保證news信息表實(shí)際存在 IOHelper.CreateFile("/newsSiteMap.xml", httpRequestHelper.Get(domain+"?table=news").Trim(), true); //更多信息表可以自行添加IOHelper.CreateFile方法,table參數(shù)改為信息表名即可 Response.Write("sitemap文件生成成功!"); }}
這里面,有幾個(gè)地方錯(cuò)誤了,附注里面有寫(xiě)出來(lái)的,也有沒(méi)有寫(xiě)出來(lái)的。還是要經(jīng)過(guò)摸索,經(jīng)過(guò)不斷的調(diào)試后,才能找到真正準(zhǔn)確的。<route urlConstraint="^buildSiteMap.cshtml$" viewPath="siteMap/siteMap.cshtml" httpcacheSolutionId="0" title=""></route>
這里的意思就是類(lèi)似于一種快捷方式的作用,把buildSiteMap.cshtml 這個(gè)文件指向真正的文件。嫌麻煩的話(huà)也可以不加,到時(shí)候直接輸入真實(shí)路徑就行了。http://localhost:800/buildSiteMap.cshtml
<mobile:mobile type="pc,mobile">
:自適應(yīng)網(wǎng)頁(yè)http://www.pageadmin.net/jianzhan/@(item.Id).cshtml
string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);<loc>@url</loc>
@{ Layout = null; string table = Request.QueryString["table"]; string domain = "https://www.iappi.cn/buildSiteMap.cshtml";//l改為您的網(wǎng)站域名,必須是外網(wǎng)域名 //生成欄目siteMap if (table=="column") { <?xml version="1.0" encoding="utf-8" ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/"> @foreach (var item in Html.GetColumnList().Where(c => c.Show == 1 && c.ColumnType <= 2)) { string url = Html.ColumnUrl((int)(item.Id)); <url> <loc>@url</loc> <lastmod>@DateTime.Now.ToString("yyyy-MM-dd")</lastmod> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> } </urlset> } //生成信息表的siteMap else if (!string.IsNullOrEmpty(table)) { <?xml version="1.0" encoding="utf-8" ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> @foreach (var item in Html.InfoDataList(new { Table = table, ShowNumber = 1500 })) { string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id); <url> <loc>@url</loc> <lastmod>@item.Thedate.ToString("yyyy-MM-dd")</lastmod> <changefreq>weekly</changefreq> <priority>0.5</priority> </url> } </urlset> } else { HttpRequestHelper httpRequestHelper = new HttpRequestHelper(); //生成欄目siteMap文件 IOHelper.CreateFile("/columnSiteMap.xml", httpRequestHelper.Get(domain+"?table=column").Trim(), true); //生成product表的siteMap文件,必須保證news信息表實(shí)際存在 IOHelper.CreateFile("/productSiteMap.xml", httpRequestHelper.Get(domain+"?table=product").Trim(), true); //生成news表的siteMap文件,必須保證news信息表實(shí)際存在 IOHelper.CreateFile("/newsSiteMap.xml", httpRequestHelper.Get(domain+"?table=news").Trim(), true); //更多信息表可以自行添加IOHelper.CreateFile方法,table參數(shù)改為信息表名即可 Response.Write("sitemap文件生成成功!"); }}
存在的問(wèn)題:生成了三個(gè)sitemap.xml ,而不是一個(gè)完整的文件。關(guān)鍵詞:方法,地圖,系統(tǒng),創(chuàng)建
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
客戶(hù)&案例
營(yíng)銷(xiāo)資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。