简体   繁体   中英

Rewrite URL to a more meaningful URL - C#

I am pulling in some URLs from following SQL table with following columns:

  • Name - Contains the Name of site
  • URL - Contains the URL of site

I am then generating dynamic HyperLinks and attaching them to a gridview column:

protected void grdReport_Bnd(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Cells[1].Visible = false;
        e.Row.Cells[2].Visible = false;


        string qry = e.Row.Cells[2].Text;   // Pulling the URL
        string username = (string)Session[Constants.AssociateID];  // Pulling associate ID frpm session.
        string qry1 = qry + "?ID=" + username;   // Passing the associate ID to the URL
        string txt = e.Row.Cells[1].Text.ToString();   // Pulling the text to display on hyperlink.

        HyperLink lnk = new HyperLink();
        lnk.Text = txt;
        lnk.NavigateUrl = qry1;
        lnk.Attributes.Add("Border", "0");
        lnk.Attributes.Add("Target", "_blank");
        e.Row.Cells[3].Controls.Add(lnk);
    }
}

Now I need to hide this resultant URL. For example the URL at the hyperlink may be: http://1.20.40.40:8050/?ID=123456 which should be displayed as http://mysite.com/ABC where abc is the text from hyperlink and mysite.com is the site where this hyperlink is getting displayed.

I have seen various examples but could not understand them.

Well I figured out that a simple rewrite won't work in this case. Hence, I have now added different pojects under one solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM