ASP.Net 和 NameValueCollection

发布于 2024-08-23 19:58:45 字数 788 浏览 2 评论 0原文

我有以下方法:

public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl)

fullUrl 的值为:

http://localhost:50435/page/view.aspx?si=00&us=admin&ut=smt&

当我这样做时:

NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);

我得到:

{http%3a%2f %2flocalhost%3a50435%2fpage%2fview.aspx%3fsi=00&us=admin&ut=smt&}

但是我需要获取这个页面的QueryString中的参数,用这个值,我无法获取“si”值,因为启动查询字符串的问号已被编码。 所以我想:“嗯...我应该尝试执行 HttpUtility.HtmlEncode()”

但是 HtmlEncode 方法返回 void:但是此方法的第二个参数将值发送到 TextWriter。但它不是 NameValueCollection。

也许解决方案很简单......但我看不到它。

I have the following method:

public object[] GetEventsByUser(DateTime start, DateTime end, string fullUrl)

The value of the fullUrl is:

http://localhost:50435/page/view.aspx?si=00&us=admin&ut=smt&

When I do:

NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);

I get:

{http%3a%2f%2flocalhost%3a50435%2fpage%2fview.aspx%3fsi=00&us=admin&ut=smt&}

But I need to obtain the parameters in the QueryString of this page, and with this value, I cannot obtain the "si" value, because the question mark, that starts the querystring is encoded.
So I thought: "humm... I should try to do the HttpUtility.HtmlEncode()"

However the method HtmlEncode returns void: However the second parameter of this method sends the value to a TextWriter. But it isn't the NameValueCollection.

Maybe the solution is simple... but I cannot see it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终止放荡 2024-08-30 19:58:45

您需要在解析之前将其修剪为仅查询字符串,如下所示:

if (fullUrl.Contains("?")) {
  fullUrl = fullUrl.Substring(fullUrl.IndexOf("?") + 1);
}
NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);

You need to trim it down to just the querystring before parsing, like this:

if (fullUrl.Contains("?")) {
  fullUrl = fullUrl.Substring(fullUrl.IndexOf("?") + 1);
}
NameValueCollection qscoll = HttpUtility.ParseQueryString(fullUrl);
泅人 2024-08-30 19:58:45

你可以尝试:

var si = Request["si"];
var user = Request["us"];
//etc.

You could try:

var si = Request["si"];
var user = Request["us"];
//etc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文