在IIS 6 / ASP.NET web表单记录服务器范围内的请求数据(包括POST数据) [英] Logging server-wide request data (including POST data) in IIS 6 / ASP.NET webforms

查看:1541
本文介绍了在IIS 6 / ASP.NET web表单记录服务器范围内的请求数据(包括POST数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是大局。我们正在运行在IIS 6承载几个网站和应用程序的服务器,而我们在整个​​事情略有不同的设置移动到不同的数据中心的过程。我们已经通知我们的用户,并更新了我们的DNS信息,这样理论上每个人都愉快地打从第一天在新的服务器,但我们知道,有人难免会漏掉。

Here's the big picture. We're running a server in IIS 6 that hosts several web sites and applications, and we're in the process of moving the whole thing to a different data center with a slightly different setup. We've notified our users and updated our DNS info so that theoretically everyone will be happily hitting the new server from day 1, but we know that someone will inevitably fall through the cracks.

这会希望有一个监听器​​页/处理器,将接收的所有的请求到服务器并记录整个请求到一个文本文件,其中包括(尤其是)POST数据的权力。

The powers that be want a "Listener" page/handler that will receive all requests to the server and log the entire request to a text file, including (especially) POST data.

这就是我卡住了。我不知道如何实现一个单一的处理程序,将接收到服务器的所有请求。我隐约明白IIS 6重定向选项,但他们似乎都失去重定向POST数据。我也知道一些关于IIS 6的内置日志记录,但是却忽略了POST数据,以及

That's where I'm stuck. I don't know how to implement a single handler that will receive all requests to the server. I vaguely understand IIS 6 redirection options, but they all seem to lose the POST data on the redirect. I also know a little about IIS 6's built-in logging, but it ignores POST data as well.

有一个简单的(ISH)的方式来路由所有对服务器的请求,使它们都打出单处理器,同时保持后的数据?

Is there a simple(ish) way to route all requests to the server so that they all hit a single handler, while maintaining post data?

编辑:这是在的WebForms,如果该事项,但其他解决方案(如小)是绝对值得考虑。

This is in WebForms, if that matters, but other solutions (if small) are definitely worth considering.

推荐答案

如果所有的请求都POST对ASP.NET表单,那么你可以一个插件的HttpModule 来捕捉和记录此数据。

If all the requests are POST's to ASP.NET forms then you could plugin a HttpModule to capture and log this data.

您就不必重新构建所有的应用程序要么部署此。所有则需是删除的HttpModule 到每个应用程序的 / bin中文件夹并将其添加到<&的HttpModules GT;你的的web.config 文件部分。例如:

You wouldn't have to rebuild all your applications to deploy this either. All it would take is to drop the HttpModule into each application's /bin folder and add it to the <httpModules> section of your web.config files. For example:

using System;
using System.Diagnostics;
using System.Web;

public class SimpleLogger : IHttpModule
{
  private HttpApplication _application;

  public void Dispose() { }

  public void Init(HttpApplication context)
  {
    _application = context;
    context.BeginRequest += new EventHandler(Context_BeginRequest);
  }

  void Context_BeginRequest(object sender, EventArgs e)
  {
    foreach (string key in _application.Request.Form.AllKeys)
    {
      // You can get everything on the Request object at this point
      // Output to debug but you'd write to a file or a database here.
      Debug.WriteLine(key + "=" + _application.Request.Form[key]);
    }
  }
}

在你的的web.config 文件中添加记录:

In your web.config file add the logger:

<httpModules>
  <add name="MyLogger" type="SimpleLogger, SimpleLogger"/>
</httpModules>

不过要小心。如果您的站点捕获信用卡信息或其他敏感数据。您可能需要确保这是从谁应该没有必要看到这些信息企业人事过滤掉,或者对其进行加密,并离开。

Be careful though. If your site captures credit card details or other sensitive data. You may need to ensure this is filtered out or have it encrypted and away from personel who should have no need to see this information.

此外,如果你记录到文件,确保日志文件是任何面向公众的Web文件夹内。

Also if you're logging to files, make sure the log files are outside any public facing web folders.

这篇关于在IIS 6 / ASP.NET web表单记录服务器范围内的请求数据(包括POST数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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