PDA

View Full Version : مشکل به هنگام گذاشتن کد در حلقه برای ساخت سایت مپ



sun2rise
پنج شنبه 05 تیر 1393, 05:12 صبح
من برای ساخت سایت مپ یک فایل aspx میسازم و کدهای زیر رو داخل پیج لود آن می نویسم به صورت دستی که اطلاعات رو وارد میکنم سایت مپ بدون هیچ نقصی باز میشه ولی وقتی که میخوام کدها رو بذارم داخل حلفه به مشکل برمیخورم که عکسش رو گذاشتم
لطفا راهنمایی کنید که باید چطوری عمل کنم

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;

public partial class SiteMap : System.Web.UI.Page
{
public string changefreq = "hourly";
public string priority = "0.9";
protected void Page_Load(object sender, EventArgs e)
{
//string text = "select * from Tbl_Content order by Cnt_ID DESC";

Response.Clear();
Response.ContentType = "text/xml";
using (XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
{
string text = "select * from Tbl_Content";
Dal run = new Dal();
DataTable dt = new DataTable();
dt = run.Withquery(text);
int count = Convert.ToInt32(dt.Rows.Count);
int i;
for (i = 0; i < count; i++)
{

string Loc = "http://localhost:1622/SiteMap.aspx?id=" + dt.Rows[i]["Cnt_ID"].ToString();


writer.WriteStartElement("url");
writer.WriteElementString("loc", Loc);
writer.WriteElementString("changefreq", changefreq);
writer.WriteElementString("priority", priority);
writer.WriteEndElement();
writer.Flush();
}
}

Response.End();
}
}





120501

Mag-Mag
پنج شنبه 05 تیر 1393, 10:09 صبح
سلام
اون قسمتی که نوشتی :
string Loc = "http://localhost:1622/SiteMap.aspx?id=" + dt.Rows[i]["Cnt_ID"].ToString();
درست نیست
باید اینطوری بنوسی

string Loc = Server.MapPath("SiteMap.aspx?id=" + dt.Rows[i]["Cnt_ID"].ToString() + "");