Get url parameters from a string in .NET

前端 未结 13 1643
一个人的身影
一个人的身影 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:01

    Use static ParseQueryString method of System.Web.HttpUtility class that returns NameValueCollection.

    Uri myUri = new Uri("http://www.example.com?param1=good¶m2=bad");
    string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("param1");
    

    Check documentation at http://msdn.microsoft.com/en-us/library/ms150046.aspx

提交回复
热议问题