Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add one parameter to current url in c#

Tags:

c#

asp.net

I have 2 links

 <li class="active">
  <a href="<%#CurrentSearchUrl%>"><span>Current search Page
 </span></a> 

  <li><a href="<%#CurrentSearchUrlParam%>"><span>Add param </span>
      </a> 

in the Page_Load

    CurrentSearchUrl = Request.Url.AbsoluteUri;
    CurrentSearchUrlParam = Request.Url+"&discount=1";

param is added but url is not correct my current url is

http://localhost:1067/search/default.aspx?q=test

I want to add one parameter, the desired result should be

http://localhost:1067/search/default.aspx?q=test&discount=1

Thanks in advance

like image 643
Alex Avatar asked Nov 27 '22 17:11

Alex


1 Answers

        var uriBuilder = new UriBuilder(Request.Url.AbsoluteUri);
        var paramValues = HttpUtility.ParseQueryString(uriBuilder.Query);
        paramValues.Add("param1", "value1");
        paramValues.Add("param2", "value2");
        uriBuilder.Query = paramValues.ToString();

        Link1.HRef=uriBuilder.Uri;
like image 111
Victor Mukherjee Avatar answered Dec 05 '22 01:12

Victor Mukherjee