How to get the parameter from a relative URL string in C#?

Daniel Congrove

What's the most efficient way to get a specific parameter from a relative URL string using C#?

For example, how would you get the value of the ACTION parameter from the following relative URL string:

string url = "/page/example?ACTION=data&FOO=test";

I have already tried using:

var myUri = new Uri(url, UriKind.Relative);
String action = HttpUtility.ParseQueryString(myUri.Query).Get("ACTION");

However, I get the following error:

This operation is not supported for a relative URI.

alexm
 int idx = url.IndexOf('?');
 string query = idx >= 0 ? url.Substring(idx) : "";
 HttpUtility.ParseQueryString(query).Get("ACTION");

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How to get type from String?

来自分类Dev

how to rewrite relative url in minified css with cssmin?

来自分类Dev

jQuery- How to get the GET variable from a URL

来自分类Dev

How to get track ID from URL using the SoundCloud API

来自分类Dev

Xamarin ndk get string from c function as return value

来自分类Dev

PHP Get Relative Path from Parent to Included File

来自分类Dev

How to get 8 random unique elements from a string array?

来自分类Dev

How to randomly get a string from a collection but prefer strings at the beginning of the collection

来自分类Dev

how to get array key from string array in java

来自分类Dev

convert parameter value from a String to a DateTime?

来自分类Dev

How to trim and split URL string

来自分类Dev

How to get annotated method parameter and his annotation

来自分类Dev

How to remove � from a String?

来自分类Dev

I want to get numeric data from string. How to do that in python?

来自分类Dev

How can I get the x/y location of a touch relative to the entire view when I touch a button?

来自分类Dev

How to work with string.format for nth parameter dynamically generated jquery

来自分类Dev

How to make a Node from a String?

来自分类常见问题

How to auto-generate a C# class file from a JSON string

来自分类Dev

在新的Rewrite-URL中删除不需要的Get-Parameter

来自分类Dev

How to get Image.Source as string

来自分类Dev

How to get length of a string using strlen function

来自分类Dev

How to get string for current namespace in Macro

来自分类Dev

Get parameter name

来自分类Dev

Is it possible to get String value back from its hash code?

来自分类Dev

Safely get string input from user including spaces

来自分类Dev

How to retrieve values from junction table as a String?

来自分类Dev

How to Remove JavaScript Remnants from String in PHP

来自分类Dev

How to create a list of Tab from a list of String?

来自分类Dev

How to execute a GDB command from a string variable?

Related 相关文章

  1. 1

    How to get type from String?

  2. 2

    how to rewrite relative url in minified css with cssmin?

  3. 3

    jQuery- How to get the GET variable from a URL

  4. 4

    How to get track ID from URL using the SoundCloud API

  5. 5

    Xamarin ndk get string from c function as return value

  6. 6

    PHP Get Relative Path from Parent to Included File

  7. 7

    How to get 8 random unique elements from a string array?

  8. 8

    How to randomly get a string from a collection but prefer strings at the beginning of the collection

  9. 9

    how to get array key from string array in java

  10. 10

    convert parameter value from a String to a DateTime?

  11. 11

    How to trim and split URL string

  12. 12

    How to get annotated method parameter and his annotation

  13. 13

    How to remove � from a String?

  14. 14

    I want to get numeric data from string. How to do that in python?

  15. 15

    How can I get the x/y location of a touch relative to the entire view when I touch a button?

  16. 16

    How to work with string.format for nth parameter dynamically generated jquery

  17. 17

    How to make a Node from a String?

  18. 18

    How to auto-generate a C# class file from a JSON string

  19. 19

    在新的Rewrite-URL中删除不需要的Get-Parameter

  20. 20

    How to get Image.Source as string

  21. 21

    How to get length of a string using strlen function

  22. 22

    How to get string for current namespace in Macro

  23. 23

    Get parameter name

  24. 24

    Is it possible to get String value back from its hash code?

  25. 25

    Safely get string input from user including spaces

  26. 26

    How to retrieve values from junction table as a String?

  27. 27

    How to Remove JavaScript Remnants from String in PHP

  28. 28

    How to create a list of Tab from a list of String?

  29. 29

    How to execute a GDB command from a string variable?

热门标签

归档