ALTER PROCEDURE dbo.aspnet_UsersInRoles_IsUserInRole
@ApplicationName NVARCHAR(256),
@UserName NVARCHAR(256),
@RoleName NVARCHAR(256)
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN(2)
/*返回@ApplicationId,不存在返回2*/
DECLARE @UserId UNIQUEIDENTIFIER
SELECT @UserId = NULL
DECLARE @RoleId UNIQUEIDENTIFIER
SELECT @RoleId = NULL
SELECT @UserId = UserId
FROM dbo.aspnet_Users
WHERE LoweredUserName = LOWER(@UserName) AND ApplicationId = @ApplicationId
/*查询此用户的ID*/
IF (@UserId IS NULL)
RETURN(2)
SELECT @RoleId = RoleId
FROM dbo.aspnet_Roles
WHERE LoweredRoleName = LOWER(@RoleName) AND ApplicationId = @ApplicationId
/*查询此角色的ID*/
IF (@RoleId IS NULL)
RETURN(3)
IF (EXISTS( SELECT * FROM dbo.aspnet_UsersInRoles WHERE UserId = @UserId AND RoleId = @RoleId))
/*判断此用户是否存在于此角色中*/
RETURN(1)
ELSE
RETURN(0)
END
@ApplicationName NVARCHAR(256),
@UserName NVARCHAR(256),
@RoleName NVARCHAR(256)
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN(2)
/*返回@ApplicationId,不存在返回2*/
DECLARE @UserId UNIQUEIDENTIFIER
SELECT @UserId = NULL
DECLARE @RoleId UNIQUEIDENTIFIER
SELECT @RoleId = NULL
SELECT @UserId = UserId
FROM dbo.aspnet_Users
WHERE LoweredUserName = LOWER(@UserName) AND ApplicationId = @ApplicationId
/*查询此用户的ID*/
IF (@UserId IS NULL)
RETURN(2)
SELECT @RoleId = RoleId
FROM dbo.aspnet_Roles
WHERE LoweredRoleName = LOWER(@RoleName) AND ApplicationId = @ApplicationId
/*查询此角色的ID*/
IF (@RoleId IS NULL)
RETURN(3)
IF (EXISTS( SELECT * FROM dbo.aspnet_UsersInRoles WHERE UserId = @UserId AND RoleId = @RoleId))
/*判断此用户是否存在于此角色中*/
RETURN(1)
ELSE
RETURN(0)
END