Get url parameters from a string in .NET

前端 未结 13 1639
一个人的身影
一个人的身影 2020-11-22 11:38

I\'ve got a string in .NET which is actually a url. I want an easy way to get the value from a particular parameter.

Normally, I\'d just use Request.Params[

13条回答
  •  渐次进展
    2020-11-22 12:02

    This is actually very simple, and that worked for me :)

            if (id == "DK")
            {
                string longurl = "selectServer.aspx?country=";
                var uriBuilder = new UriBuilder(longurl);
                var query = HttpUtility.ParseQueryString(uriBuilder.Query);
                query["country"] = "DK";
    
                uriBuilder.Query = query.ToString();
                longurl = uriBuilder.ToString();
            } 
    

提交回复
热议问题