你将如何审核ASP.NET成员表,同时记录哪些用户所做的更改? [英] How would you audit ASP.NET Membership tables, while recording what user made the changes?

查看:182
本文介绍了你将如何审核ASP.NET成员表,同时记录哪些用户所做的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用基于触发器的方法来审计记录,我记录在数据库中的表所做的更改的历史。我使用(一个静态的SQL Server登录)来记录哪些用户进行更改的方法涉及运行在每个数据库连接开始时的存储过程。触发器记录审计行时使用该用户名。 (该触发器由产品OmniAudit提供。)

Using a trigger-based approach to audit logging, I am recording the history of changes made to tables in the database. The approach I'm using (with a static sql server login) to record which user made the change involves running a stored procedure at the outset of each database connection. The triggers use this username when recording the audit rows. (The triggers are provided by the product OmniAudit.)

不过,ASP.NET成员表主要是通过会员的API访问。我需要在当前用户的身份通过时,成员身份API开放其数据库连接。我试着子类的MembershipProvider,但我不能访问底层的数据库连接。

However, the ASP.NET Membership tables are accessed primarily through the Membership API. I need to pass in the current user's identity when the Membership API opens its database connection. I tried subclassing MembershipProvider but I cannot access the underlying database connection.

看起来这将是一个常见的​​问题。有谁知道,我们可以访问任何挂钩时,ASP.NET成员使得其数据库连接?

It seems like this would be a common problem. Does anyone know of any hooks we can access when the ASP.NET Membership makes its database connection?

推荐答案

更新2:
没有对AOP正面看起来不错,我很害怕 - 见<一href=\"http://stackoverflow.com/questions/2912300/is-is-possible-to-intercept-a-constructor-on-a-class-you-do-not-own\">http://stackoverflow.com/questions/2912300/is-is-possible-to-intercept-a-constructor-on-a-class-you-do-not-own

和在评论暗示,它看起来像最好的办法是使用提供程序工具包的实现提供者和您连线勾成 SqlConnectionHelper.GetConnection()

And as alluded to in comments, it looks like the best bet is to use the Provider Toolkit's implementation of the providers and wire your hook into SqlConnectionHelper.GetConnection()

我用的工具包code,我已经清理了相当大,可靠多年,没有任何问题。让我确认在4.0和打包起来,如果你有兴趣。

I use the toolkit code, which I have cleaned up considerably, reliably for years with no problems. Let me confirm on 4.0 and package it up if you are interested.

更新:

好吧,我想我更好地了解你的需要,告诉我,如果我是正确的:

Ok, I think I better understand your need, tell me if I am correct:

您需要正在使用由供应商的实际连接?

You need the actual connection that is being used by the provider?

SqlMembershipProvider的利用一个辅助类, System.Web.DataAccess.SqlConnectionHolder ,因为它的所有数据访问。

SqlMembershipProvider utilizes a helper class, System.Web.DataAccess.SqlConnectionHolder, for all of it's data access.

我没有这样做,而是从我收集的,你可以拦截来电来构建这个对象使用AOP实现,比如城堡DynamicProxy(或利用它的图书馆之一),让你连接在那里。

I have not done this, but from what I have gathered, you could intercept calls to build this object using an AOP implementation such as Castle DynamicProxy (or one of the libraries that leverage it) and get your connection there.

能有人与更多的经验证实或否认这一点?

Could some one with more experience confirm or deny this?

原来的答复:

无需从SqlMembershipProvider的派生。刚进去,并得到你所需要的。

No need to derive from SqlMembershipProvider. Just go in and get what you need.

string connectionString = 
   typeof(SqlMembershipProvider)
   .GetField("_sqlConnectionString",BindingFlags.NonPublic | BindingFlags.Instance)
   .GetValue(Membership.Provider);

这篇关于你将如何审核ASP.NET成员表,同时记录哪些用户所做的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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