实体框架和模拟
我将实体框架和 ASP.NET 动态数据合并到现有应用程序中,该应用程序设置为在 web.config 中使用 impersonation="true",但是以前的开发人员选择了一种方法,将每个应用程序恢复为应用程序池标识他们进行的 DAL 调用
private WindowsImpersonationContext context = null;
public void RevertToAppPool()
{
if (!WindowsIdentity.GetCurrent().IsSystem)
{
context = WindowsIdentity.Impersonate(System.IntPtr.Zero);
}
}
public void UndoImpersonation()
{
if (context != null)
{
context.Undo();
}
}
我被要求在使用实体框架时保留此行为...考虑到实体对象在各处使用(在 LINQ to EF 查询、手动调用、框架的幕后调用中)等),哪里会是分部类中的适当位置可以为每次调用对 RevertToAppPool 和 UndoImpersonation 进行适当的调用?
I'm incorporating Entity Framework and ASP.NET Dynamic Data into an existing application that is setup to use impersonation="true" in the web.config, however the previous developers chose an approach where they revert back to the app pool identity for each DAL call they made
private WindowsImpersonationContext context = null;
public void RevertToAppPool()
{
if (!WindowsIdentity.GetCurrent().IsSystem)
{
context = WindowsIdentity.Impersonate(System.IntPtr.Zero);
}
}
public void UndoImpersonation()
{
if (context != null)
{
context.Undo();
}
}
I've been asked to preserve this behavior while using Entity Framework ...given that the entity objects are used all over the place (in LINQ to EF queries, manual calls, behind-the-scenes calls by the framework etc.), where would be the appropriate places in the partial classes to make the appropriate calls to RevertToAppPool and UndoImpersonation for every call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能需要创建自定义 实体框架提供程序包装器 并在包装连接中恢复模拟之前连接打开并在连接打开后将其放回去(希望这足够了)。如果您使用 SQL 身份验证来代替数据库,您的生活会轻松得多。
模拟并恢复数据访问看起来是一个非常奇怪的解决方案。我想知道该应用程序中模拟的意义是什么?
You would most probably need to create custom Entity framework provider wrapper and in wrapped connection revert impersonation before connection opening and put it back after connection has been openned (hopefully it will be enough). You will have much easier live if you use SQL authentication for database instead.
Imperesonation with reverting back for data access looks like pretty odd solution. I wonder what is the point of impersonation in that application?