确定哪些服务器(在Web场)的asp.net Ajax请求来自何处? [英] determining which server (in a web farm) the asp.net ajax request came from?

查看:166
本文介绍了确定哪些服务器(在Web场)的asp.net Ajax请求来自何处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想如何才能找出网页是由担任该服务器:我会做类似的东西放了隐藏变量已经从它得到处理的服务器的IP地址或服务器名称在页面上这样做。那些发生,因为一个局部回传:但是我的asp.net Ajax请求呢?我不得不把隐藏变量更新面板,但如果有很多更新面板的页面?

I was thinking how we can find out which server the page was served from: I'd do so by doing something like put a hidden variable on the page which has the IP or server name from the server it got processed. But what do I do for asp.net ajax requests: those that happen as a partial postback? I'd have to put the hidden variable in the update panel, but what if there are many update panels in the page?

我检查了另一个<一个href=\"http://stackoverflow.com/questions/3856979/how-to-identify-which-web-server-in-a-farm-served-a-request\">SO帖子,但解决的办法是IIS 7什么是IIS6等价?我们又如何能读头?到哪里找?

I checked out another SO post, but the solution was for iis 7. What is the equivalent for iis6? And how can we read the header? Where to look?

推荐答案

您可以通过打开站点的属性,然后单击HTTP头选项卡上设置通过IIS MMC IIS6自定义页眉:

You can set IIS6 custom headers via IIS MMC by opening a site's properties then clicking on the HTTP Headers tab:

您也可以使用 ADSUTIL (在找到C:\\的Inetpub \\ AdminScripts


cscript adsutil set w3svc/1/root/HttpCustomHeaders "X-Served-By:Server-001"

上面的命令将配置HTTP头默认网站。

The command above will configure the HTTP Headers for the default website.

使用时要小心 ADSUTIL ,因为这将覆盖任何现有的头已经配置。

Be careful when using adsutil as this will overwrite any existing headers already configured.

要设置多个头做的:


cscript adsutil set w3svc/1/root/HttpCustomHeaders "X-Served-By:Server-001" "X-Powered-By:ASP.NET"

更新:

关于访问客户端的响应头,如果您使用的是ASP.NET AJAX更新面板那么这个脚本添加到您的网页的末尾:

With regard to accessing the response headers on the client, if you're using an ASP.NET AJAX update panel then add this script to the end of your page:

<script type="text/javascript" language="javascript">
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endPageRequest);

  function endPageRequest(sender, args) {

    var allHeaders = args._response._xmlHttpRequest.getAllResponseHeaders();
    var headers = allHeaders.split('\n');

    // At this point you have a string array of response headers.

    // Or you can get an individual header:
    var header = args._response._xmlHttpRequest.getResponseHeader("MyHeader");

  }
</script>

这将钩到页面请求管理器,使Ajax请求完成时,你还可以得到具有响应头的副本基本XMLHtt prequest对象的可见性。

This will hook into the page request manager such that when the Ajax request completes you also get visibility of the underlying XMLHttpRequest object which has a copy of the response headers.

您可以做同样的事情用jQuery:

You can do something similar with jQuery:

$.ajax({
  url: "/Home/HeadTest",
  success: function (data, textStatus, xhr) {
    var header = xhr.getResponseHeader("MyHeader");                 
  }
});

这篇关于确定哪些服务器(在Web场)的asp.net Ajax请求来自何处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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