在c#中输出操作的QueryString [英] Outputing a manipulated QueryString in c#

查看:619
本文介绍了在c#中输出操作的QueryString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码我得到一个不错的格式化字符串:

Using the following code I get a nice formatted string:

Request.QueryString.ToString 

给我类似的东西:& hello = world& microsoft = sucks

Gives me something like: &hello=world&microsoft=sucks

但是当我使用这个代码将集合克隆到另一个对象(相同类型)时,我从ToString()方法中返回Type()。

But when I use this code to clone the collection to another object (of the same type) I get the Type() back from the ToString() method instead.

System.Collections.Specialized.NameValueCollection variables = new System.Collections.Specialized.NameValueCollection(Request.QueryString);
if (!string.IsNullOrEmpty(variables["sid"]))
    variables.Remove("sid");
Response.Write(variables.ToString());

是否有一个更整洁的方法来输出它,而不是手动查找和构建字符串?

Is there a tidier way to output it rather than looking and building the string manually?

推荐答案

您还可以使用Reflector将 HttpValueCollection 类解压缩为您自己的,然后。

You can also use Reflector to extract the HttpValueCollection class into your own, and use it then.

这篇关于在c#中输出操作的QueryString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆