1
Reply

add fake query string to duplicate sitemap URL

Hazel Mahmud

Hazel Mahmud

Feb 23 2016 10:25 PM
834
hello..i have created dynamic sitemap using XMLTextWriter. i have succeeded to retrieve from database but unfortunately there are some duplicate URL which sitemap did not allow. how do i add fake querystring to the duplicate URL so that it works well..please help..below are my aspx.cs code..
 
 
using (XmlTextWriter writer = new XmlTextWriter(Server.MapPath("web.sitemap"), Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteRaw("\n");
writer.WriteStartElement("siteMap");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");

writer.WriteRaw("\n");
writer.WriteRaw("\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/index.aspx");
writer.WriteAttributeString("title", "Home");
writer.WriteRaw("\n");
writer.WriteRaw("\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/MainPage/MyProfile.aspx?Value=" + lblsystemID.Text);
writer.WriteAttributeString("title", "Self-Service");
using (SqlConnection con = ClassConn.GetPortalCon())
{

SqlCommand cmd = new SqlCommand("ret_Menu", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@userID", nopkj);
cmd.Parameters.AddWithValue("@systemID", lblsystemID.Text);

SqlDataReader sc = cmd.ExecuteReader();

if (sc.HasRows)
{
while (sc.Read())
{

var menuID = sc["menuID"].ToString();

writer.WriteRaw("\n"); writer.WriteRaw("\t\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", sc["menuPath"].ToString());
writer.WriteAttributeString("title", sc["menu_label"].ToString());
writer.WriteAttributeString("description", sc["menu_label"].ToString());

using (SqlConnection con1 = ClassConn.GetPortalCon())
{

SqlCommand cmd1 = new SqlCommand("ret_SubMenuSiteMap", con1);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@userID", nopkj);
cmd1.Parameters.AddWithValue("@systemID", lblsystemID.Text);
cmd1.Parameters.AddWithValue("@menuID", menuID);

SqlDataReader sc1 = cmd1.ExecuteReader();

if (sc1.HasRows)
{
while (sc1.Read())
{
writer.WriteRaw("\n");
writer.WriteRaw("\t\t\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", sc1["subMenuPath"].ToString());
writer.WriteAttributeString("title", sc1["submenu_label"].ToString());
writer.WriteAttributeString("description", sc1["submenu_label"].ToString());
writer.WriteEndElement();
}
}


}writer.WriteEndElement();

}
}
}

writer.WriteEndElement();
writer.WriteEndDocument();

Answers (1)