How do I encode an URL?

后端 未结 4 1097
猫巷女王i
猫巷女王i 2020-12-31 11:00

When I run my project I get the url http://localhost:5973/PageToPageValuePass/Default.aspx I want to Encode the URL since sometimes I need to transfer data fro

4条回答
  •  醉酒成梦
    2020-12-31 11:49

    say you want to create a link with some parameters you can use it as follows:

    aspx:

    Click Here

    code behind:

    myLink.Href = Page.ResolveClientUrl("~/MyPage.aspx") + "?id=" + 
       Server.UrlEncode("put here what ever you want to url encode"); 
    

    Or as in your question:

    myLink.Href = "http://www.google.com/")+Server.UrlEncode("C#");
    

    this will put in html:

    
    

提交回复
热议问题