使用 C# 从相对 URL 字符串获取特定参数的最有效方法是什么?
例如,如何从以下相对 URL 字符串中获取 ACTION
参数的值:
string url = "/page/example?ACTION=data&FOO=test";
我已经尝试过使用:
var myUri = new Uri(url, UriKind.Relative);
String action = HttpUtility.ParseQueryString(myUri.Query).Get("ACTION");
但是,我收到以下错误:
This operation is not supported for a relative URI.
最佳答案
int idx = url.IndexOf('?');
string query = idx >= 0 ? url.Substring(idx) : "";
HttpUtility.ParseQueryString(query).Get("ACTION");
关于c# - 如何从 C# 中的相对 URL 字符串获取参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38645204/