如何从使用C#在asp.net中查询字符串中删除的项目?字符串、项目、asp、net

2023-09-02 11:49:36 作者:御喵

我想删除语言从我的网址查询字符串。我怎样才能做到这一点? (使用Asp.net 3.5,C#)

  Default.aspx的代理= 10安培;语言= 2
 

我想删除语言= 2,但语言将是第一个,中间或最后。所以我也会有这种

 的Default.aspx?代理= 20
 

解决方案

我回答了的类似的问题在不久前的。基本上,最好的办法是使用类 HttpValueCollection ,其中查询字符串属性实际上,不幸的是它的内部在.NET框架。 你可以使用反射来抓住它(并把它变成你的Utils类)。这样,您就可以操纵像一个NameValueCollection中的查询字符串,但所有的url编码/解码的问题采取的照顾你。

HttpValueCollection 扩展的NameValueCollection ,并拥有一个构造函数连接codeD查询字符串(&符号和问号包括),它覆盖了一个的ToString()方法后重建从底层集合的查询字符串。

wpf字符串格式化来实现空格占位 对齐问题Arial字符宽度不一致ChitGPT真牛

I want remove "Language" querystring from my url. How can i do this ? (using Asp.net 3.5 , c#)

Default.aspx?Agent=10&Language=2

I want to remove "Language=2", but language would be the first,middle or last. so i will have this

Default.aspx?Agent=20

解决方案

I answered a similar question a while ago. Basically, the best way would be to use the class HttpValueCollection, which the QueryString property actually is, unfortunately it is internal in the .NET framework. You could use Reflector to grab it (and place it into your Utils class). This way you could manipulate the query string like a NameValueCollection, but with all the url encoding/decoding issues taken care for you.

HttpValueCollection extends NameValueCollection, and has a constructor that takes an encoded query string (ampersands and question marks included), and it overrides a ToString() method to later rebuild the query string from the underlying collection.