.Net 表单 POST
我有一个客户在测试过程中向我提供了相互矛盾的信息。 我不认为他们在撒谎,而是更加困惑。 因此,我想在 ASP.Net 应用程序中设置一些简单的审核。 具体来说,当调用任何页面时,我想立即将查询字符串和/或表单 POST 数据插入日志表中。 只是原始值。
查询字符串很简单。 但似乎没有办法在不使用 BinaryRead 的情况下获取原始表单 POST 数据,如果我这样做,那么我以后就会放弃使用 Request.Form 集合。
有谁知道解决这个问题的方法吗?
编辑:tvanfosson 建议使用 Request.Params。 我一直在寻找更容易使用的东西(比如 Request.Querystring,仅用于 POST),但我想我可以轻松地循环所有参数并构建一个 name=value& 等字符串)。
I've got a client that, during testing, is giving me conflicting information. I don't think they are lying but more confused. So, I would like to setup some simple auditing in my ASP.Net application. Specifically, right when any page is called, I want to immediately insert the Querystring and/or form POST data into a log table. Just the raw values.
Querystring is easy. But there doesn't seem to be a way to get the raw form POST'ed data without using BinaryRead, and if I do that, then I screw myself out of using the Request.Form collection later on.
Does anyone know a way around this?
EDIT: tvanfosson suggested Request.Params. I was looking for something that was easier to use (like Request.Querystring, only for POST), but I guess I could just as easily loop through all params and build a string of name=value&, etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建一个自定义 HttpModule 来捕获对应用程序发出的所有请求,这样您就不需要接触每个页面,并且只能在测试期间使用它,以免降低生产性能。
一个示例实现是:
您需要将模块添加到您的 web.config
You can create a custom HttpModule to capture all request made to your application so you don't need to touch every page and you can use it only during testing just not to slow down performance in production.
A sample implementation would be:
You need to add the module to your web.config
所有表单数据应位于 Request.Params< /a>. 您需要在每个页面上执行此操作,或者可能使用 HttpModule。
[编辑] 如果您想单独获取表单参数,请使用 Request.Form,以及Request.QueryString
All of the form data should be in Request.Params. You'd need to do this on every page, though or maybe use an HttpModule.
[EDIT] If you want to get the form parameters separately use Request.Form, along with Request.QueryString
我建议针对这种类型的场景实现 HttpHandler 或 HttpModule。 您可以从 Page_Load 事件获取 POST 数据,但在这里实现此日志记录功能并不那么可维护。
I would recommend implementing and HttpHandler or an HttpModule for this type of scenario. You can get to the POST Data from the Page_Load event but implementing this logging facility here is not as maintainable.