Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to create search option in my ASP.net application to check Doctor details based on Location. If I try the below code, only home page is showing. http://localhost:56813/Metatag/Home.aspx.I want the URL to be changed as per location.Example expected URL:http://localhost:56813/Metatag/chennai/doctors/saidapet

I'm new to this technology. Please help me to sort this out.

Thanks

What I have tried:

Page Load
protected void Page_Load(object sender, EventArgs e)
{
     string page = Request.Url.Segments[Request.Url.Segments.Length - 1];
     string location = Request.Url.Segments[Request.Url.Segments.Length - 1];
     DataTable dtMeta = this.GetData(page,location);

     //Add Page Title
     this.Page.Title = dtMeta.Rows[0]["Title"].ToString();

     //Add Keywords Meta Tag
     HtmlMeta keywords = new HtmlMeta();
     keywords.HttpEquiv = "keywords";
     keywords.Name = "keywords";
     keywords.Content = dtMeta.Rows[0]["Keywords"].ToString();
     this.Page.Header.Controls.Add(keywords);

     //Add Description Meta Tag
     HtmlMeta description = new HtmlMeta();
     description.HttpEquiv = "description";
     description.Name = "description";
     description.Content = dtMeta.Rows[0]["Description"].ToString();
     this.Page.Header.Controls.Add(description);
 }

GetData Table
C#
private DataTable GetData(string page,string location)
{
    string query = "SELECT Title, Description, Keywords FROM MetaTags WHERE LOWER(Page,Location) = LOWER(@Page,@Location)";
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand(query))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@Page", page);
                cmd.Parameters.AddWithValue("@Location", location);
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                DataTable dt = new DataTable();
                sda.Fill(dt);
                return dt;
            }
        }
    }
}
Posted
Updated 9-Jan-17 21:57pm
v3
Comments
anup.bhunia 10-Jan-17 7:04am    
if i understand your question, you want to have dynamic url based on your location. To achieve that you may you asp.net mvc application template, where you could define your custom routing.
ZurdoDev 10-Jan-17 7:32am    
I think you want url rewriting. Not meta tags.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900