简体   繁体   English

如何在ASP.NET中添加常量querystring参数

[英]How to add a constant querystring parameter in ASP.NET

I have a large ASP.NET/C# application that we're currently expanding on. 我有一个目前正在扩展的大型ASP.NET/C#应用程序。 I need to add a querystring parameter to a page and have that parameter be added automatically to every request thereafter. 我需要在页面上添加一个querystring参数,然后将该参数自动添加到每个请求中。

For example, let's say the user chooses mode=1. 例如,假设用户选择mode = 1。 I need to add &mode=1 to the querystring of every single link that is clicked from that point forward. 我需要将&mode = 1添加到从该点开始单击的每个链接的查询字符串中。 At any point, the user can change the mode=2. 用户可以随时更改mode = 2。 So then I need that change to be reflected on each subsequent request. 因此,我需要将该更改反映在每个后续请求中。

And yes, I realize that what I'm basically looking for is to store a flag in either a session variable or a cookie. 是的,我意识到我基本上要寻找的是将标志存储在会话变量或cookie中。 However, we've done that and we're having issues with it not persisting correctly. 但是,我们已经做到了,但存在一些问题,该问题无法正确持久。 If nothing else, I'd like to put this in the querystring if only for testing purposes to see if the issue is simply with session/cookie state, or if somewhere in our code it's getting improperly reset. 如果没有其他问题,我只想出于测试目的将其放在查询字符串中,以查看问题是否仅在于会话/ cookie状态,或者是否在我们的代码中某处被错误地重置。

I would personally try and rework this approach as it sounds messy and it likely to cause issues down the track - sessions are perfect for this type of thing. 我个人会尝试并重新尝试这种方法,因为它听起来很杂乱,并且很可能会引起一些问题-会议非常适合此类情况。

If you really need to do this I would suggest writing up a http handler to intercept all http requests and make sure these parameters are in included in each request 如果您确实需要这样做,建议您编写一个http处理程序以拦截所有http请求,并确保每个请求中都包含这些参数

See http://support.microsoft.com/kb/308001 请参阅http://support.microsoft.com/kb/308001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM