为什么只读的Request.QueryString? [英] Why is Request.QueryString readonly?

查看:198
本文介绍了为什么只读的Request.QueryString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想没有一个重定向你不能改变服务器上的查询字符串。

I thought you couldn't change the QueryString on the server without a redirect.

但是,这code *的作品对我来说:

But this code works* for me:

<一个href=\"http://stackoverflow.com/questions/529551/how-can-i-remove-item-from-querystring-in-asp-net-using-c/1536488#1536488\">Request.QueryString编辑

我很惊讶。

因此,这里是我的关于这个问题:


  1. 为什么只读的Request.QueryString?

  2. 为什么这个code /破解工作*?

  3. 安全性如何呢,如果你改变尽快编辑完成后,双方就坏的错误或意外行为,以及对维护和理解code只读?

  4. 凡在活动周期中它将使最有意义,如果你只使用pageLoad的和OnPageRender?
  5. 请这个疯狂的编辑
  1. Why is Request.QueryString readonly?
  2. Why does this code/hack work*?
  3. How safe is it, if you change to readonly as soon as you are done editing, both regarding bad errors or unexpected behaviour, and regarding maintaining and understanding the code?
  4. Where in the event cycle would it make most sense to do this crazy edit if you are only using PageLoad and OnPageRender?

* 更多细节:

我有被分为标签项的页面。每个选项卡是一个asp:LinkBut​​ton的

I have a page with items that are grouped into tabs. Each tab is an asp:LinkButton

我希望能够直接链接到一个特定的标签。我这样做了查询参数选项卡= TABNAME'。有用。但是,当我再点击新标签,查询字符串仍然在URL,因而在查询字符串指定的标签被激活,而不是一个我点击了。

I want to be able to link directly to a specific tab. I do that with a QueryString parameter 'tab=tabName'. It works. But when I then click a new tab, the querystring is still in the Url, and thus the tab specified in the Querystring gets activated and not the one I clicked.

通过使用<一个href=\"http://stackoverflow.com/questions/529551/how-can-i-remove-item-from-querystring-in-asp-net-using-c/1536488#1536488\">Request.QueryString编辑这不会发生。然后我的解决方案作品。

By using Request.QueryString edit this does not happen. Then my solution 'works'.

先谢谢了。

推荐答案

好QueryString属性是只读的,因为它不能在一个请求被改变。显然,浏览器只将一个只有一个字符串,所以只有一个集合创建请求。黑客使用反射(即操纵code和内存)来改变的东西,你不能正常变动。本hack打破了封装和QueryString属性的设计。你不应该使用它。这使得无论从设计的角度来看感。您的查询不改变,为什么改变重presents的对象呢?只有浏览器可以发送新的查询字符串,所以你基本上是在骗你自己的code关于浏览器发送的内容。

Well the QueryString property is readonly because it cannot be changed on a single request. Obviously the browser sends only one request with only one string so only one collection is created. The hack uses reflection (i.e. manipulates the code and the memory) to change stuff that you cannot change normally. This hack breaks the encapsulation and the design of the QueryString property. You should not use it. It makes no sense from design standpoint. Your query DOES NOT change so why change the object that represents it? Only the browser can send new query string so you are basically lying to your own code about what the browser sent.

如果您想要的标签使用的URL只是使用替代的LinkBut​​ton超链接。

If you want the tabs to use the URL just use Hyperlinks instead of LinkButton.

这篇关于为什么只读的Request.QueryString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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