0

在审核了 SQL 查询后,我们注意到我们的一些最昂贵的查询是由LOWER使用该函数的 .net 身份验证框架进行的(参见下面的示例)

我们的数据库不区分大小写,因此这会造成不必要的性能损失。

我正在寻找更改这些查询的最简单方法,我假设我需要使用某种自定义成员资格提供程序。

SELECT TOP (1) 

1 AS [C1], 

[Extent1].[UserName] AS [UserName], 

[Extent1].[UserId] AS [UserId], 

[Extent2].[Email] AS [Email], 

[Extent2].[PasswordQuestion] AS [PasswordQuestion], 

[Extent2].[Comment] AS [Comment], 

[Extent2].[IsApproved] AS [IsApproved], 

[Extent2].[IsLockedOut] AS [IsLockedOut], 

[Extent2].[CreateDate] AS [CreateDate], 

[Extent2].[LastLoginDate] AS [LastLoginDate], 

[Extent1].[LastActivityDate] AS [LastActivityDate], 

[Extent2].[LastPasswordChangedDate] AS [LastPasswordChangedDate], 

[Extent2].[LastLockoutDate] AS [LastLockoutDate]

FROM   [dbo].[Users] AS [Extent1]

INNER JOIN [dbo].[Memberships] AS [Extent2] ON [Extent2].[UserId] = [Extent1].[UserId]

INNER JOIN [dbo].[Applications] AS [Extent3] ON [Extent3].[ApplicationId] = [Extent2].[ApplicationId]

WHERE ((LOWER([Extent3].[ApplicationName])) = @appName) AND ((LOWER([Extent1].[UserName])) 

= @userName)
4

1 回答 1

1

不确定是否足够简单,但对于 ASP.NET MVC 4.0,您需要创建自己的类来实现 IIdentify 和 IPrincipal 接口。之后,您将在 web.config 中引用它们。在这些类中,您可以使用您选择的任何方式来检索数据(例如,自定义查询、实体框架等)。

有关更详尽的教程,请参阅此帖子:https ://codeutil.wordpress.com/2013/05/14/forms-authentication-in-asp-net-mvc-4/#mvc-implement-custom-IPrincipal-and-身份

于 2015-12-13T08:41:09.377 回答