将传入查询字符串添加到所有传出链接/流量 C#

发布于 2024-09-30 02:49:04 字数 324 浏览 1 评论 0原文

如果我有一个名为 www.testsite.com 的页面,并且我使用 url 中的查询字符串链接到该页面,是否可以以某种方式将相同的查询字符串附加到所有传出链接/流量?

例如,假设我链接到该页面,如下所示 www.testsite.com?parameter1=somevalue 然后,在该页面上,我单击一个链接,例如 google,我希望传递参数,以便 url 为 www.google.com?parameter1=somevalue。

我知道如何手动执行此操作,但是有什么办法可以将其自动附加到网址吗?就像在发生之前捕获传出请求并添加参数一样?

谢谢!

埃里克

If i have a page called www.testsite.com and I link to that page using a querystring in the url, is it possible to attach that same querystring to all the outgoing links/traffic somehow?

For instance, say I link to that page like this www.testsite.com?parameter1=somevalue
And then, on that page I click a link to for instance google, and I would like the parameter to be passed so the url would be www.google.com?parameter1=somevalue.

I know how to do this manually, but is there someway it can be appended to the url automatically? Like catch the outgoing request before happening and add the parameter?

Thanks!

Eric

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

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

发布评论

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

评论(4

内心荒芜 2024-10-07 02:49:04

您可以使用 javascript 或使用 jQuery 的 javascript 非常简单地完成此操作,

$("a").click(function(e){
    e.preventDefault();
    window.location = $(this).attr("href") + window.location.search;
});

您可以开始使用

如果您想要非 jQuery 解决方案,

jQuery,您可以仅使用 javascript 来研究绑定事件http://www.digimantra.com/tutorials/change-onclick-function-anchor-tag-javascript/

http://forums.techarena.in/software-development/1308647.htm

you could do this pretty simply with javascript or javascript using jQuery

$("a").click(function(e){
    e.preventDefault();
    window.location = $(this).attr("href") + window.location.search;
});

that should get you started

if you wanted a non-jQuery solution you can look into binding events using javascript only

http://www.digimantra.com/tutorials/change-onclick-function-anchor-tag-javascript/

http://forums.techarena.in/software-development/1308647.htm

扎心 2024-10-07 02:49:04

您可以通过 httpmodule 实现拦截过滤器,该模块会修改您发送回客户端的 html。有关详细信息,请参阅:http://msdn.microsoft.com/en-us /library/ff649096.aspx

还有一些示例:
Http 响应过滤器
SO:获取要修改的 HTML 内容

You can implement an intercepting filter through an httpmodule which modifies the html you emit back to the client. For more details see: http://msdn.microsoft.com/en-us/library/ff649096.aspx

And a few more examples:
Http Response Filter
SO: Get HTML content for modification

枕梦 2024-10-07 02:49:04

除非您有一个输出传出链接的中心位置,否则您必须手动执行此操作(可能 Visual Studio 搜索/替换可以在此处提供帮助,但我会小心,因为您最终可能会更改您不想更改的链接)。

Unless you have a central location where you output the outgoing links, you will have to do this manually (possibly the visual studio search/replace can help here, but I would be careful as you may end up changing links you didn't want to).

迎风吟唱 2024-10-07 02:49:04

您可以使用以下方式使用查询字符串参数
您可以循环遍历所有查询字符串参数,这

int loop1, loop2;
// Load NameValueCollection object.
NameValueCollection coll = Request.QueryString; 

// Get names of all keys into a string array. String[] arr1 = coll.AllKeys; 

string parameters = "";

for (loop1 = 0; loop1 < arr1.Length; loop1++) 
{

  parameters += Server.HtmlEncode(arr1[loop1]) + "=" + coll.GetValues(arr1[loop1]);

  for (loop2 = 0; loop2 < arr2.Length; loop2++) 
  {
    parameters += Server.HtmlEncode(arr2[loop2]);

  } 
}

只是基本想法。但是您可以在不知道名称的情况下循环遍历参数。

You can use following to use Query String parameters
You can loop through all your query string parameters like this

int loop1, loop2;
// Load NameValueCollection object.
NameValueCollection coll = Request.QueryString; 

// Get names of all keys into a string array. String[] arr1 = coll.AllKeys; 

string parameters = "";

for (loop1 = 0; loop1 < arr1.Length; loop1++) 
{

  parameters += Server.HtmlEncode(arr1[loop1]) + "=" + coll.GetValues(arr1[loop1]);

  for (loop2 = 0; loop2 < arr2.Length; loop2++) 
  {
    parameters += Server.HtmlEncode(arr2[loop2]);

  } 
}

its just basic idea. But you can loop through parameters without knowing the names.

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