ASP.Net Membership.DeleteUser

标签 asp.net asp.net-membership database-permissions

在测试中,我使用的db数据库上的用户是一件大事。在生产中,他只有Execute。

我打电话的时候

Membership.DeleteUser(user)

在测试中,它起作用了。
我在生产中尝试了同样的方法,我得到了:

The DELETE statement conflicted with the REFERENCE constraint "FK__aspnet_Us__UserI__37703C52". The conflict occurred in database "Testing", table "dbo.aspnet_UsersInRoles", column 'UserId'.



在我的礼物(在Google上搜索)中,我碰到了这个link
那家伙在说什么

Error: The DELETE statement conflicted with the REFERENCE constraint "FK__aspnet_Me__UserI__15502E78". The conflict occurred in database "YourDBName", table "dbo.aspnet_Membership", column 'UserId'.

Took me a while to find a solution to this across multiple sites and options as the error and possible solutions were rather misleading. Turns out, at least in my case, it was a problem with permissions on the membership database. The user I'm using to connect had access to view the membership details within the database itself, but as part of the aspnet_Users_DeleteUser stored procedure it selects from the sysobjects table. The membership connection user apparently did not have sufficient rights to do that select so the overall delete failed.

The fix for me was to add the user to the aspnet_Membership_FullAccess role for the membership database.



但是,当我这样做时,它是行不通的。有人对如何处理有任何想法吗?

最佳答案

经过一番检查后,我发现问题是aspnet_Users_DeleteUser存储过程中的这一行:

IF ((@TablesToDeleteFrom & 1) <> 0 AND
    (EXISTS (SELECT name FROM sysobjects WHERE (name = N'vw_aspnet_MembershipUsers') AND (type = 'V'))))

还有3个其他表的3个其他类似行。问题是,如果执行存储的proc的用户无权访问vw_aspnet_MembershipUsers,则从sysobjects中进行选择时不会打开。我很好奇为什么需要整个EXISTS语句。

无论如何,以下讨论“Access to sysobjects to view user tables without having access to the user tables directly in SQL Server Security”都有答案。通过在相关 View 上授予“VIEW DEFINITION”,EXISTS语句现在将成功执行,您不必在应用程序的连接字符串中向用户授予不必要,不必要或过多的权限。

关于ASP.Net Membership.DeleteUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/473060/

相关文章:

c# - DropDownList 导致错误 : Object reference not set to an instance of an object

asp.net - 错误 HTTP 404.11 通过查询字符串传递帐户激活 token

c# - ASP.NET 4 自定义成员资格提供程序表

java - Hibernate:有没有办法以编程方式创建类似于现有表的新表?

mysql - 授予对具有特定前缀的多个表的权限

postgresql - 为什么 PostgreSQL 将用户和组合并到角色中?

c# - 排序 Gridview 不起作用

asp.net - 以编程方式刷新/更新 HttpContext.User

JQuery $.get 从自托管 Web API 返回 404 undefined

asp.net - 将一个 Asp.net Membership 数据库与多个应用程序一起使用