实体框架和模拟

发布于 2024-11-30 06:24:54 字数 609 浏览 6 评论 0原文

我将实体框架和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2024-12-07 06:24:54

您很可能需要创建自定义 实体框架提供程序包装器 并在包装连接中恢复模拟之前连接打开并在连接打开后将其放回去(希望这足够了)。如果您使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文