将Membership.GetAllUsers()转换为通用列表时出现NotSupportedException [英] NotSupportedException when casting Membership.GetAllUsers() to generic list
问题描述
例如,在获取所有用户名时,我尝试在.NET Membership.GetAllUsers()集合上使用LINQ:
I am trying to use LINQ on the .NET Membership.GetAllUsers() collection, for example when getting all usernames:
var usernames = Membership.GetAllUsers().Cast<MembershipUser>().Select(x=>x.UserName).ToList();
但是VS告诉我它不受支持.
But VS tells me that it is not supported..
成员资格是Web.Security的一部分,与MembershipUser相同
Membership is a part of Web.Security, same as MembershipUser
这是我的连接字符串(如果有任何相关性):
Here is my connection string (if that is of any relevance):
<add name="ApplicationServices" connectionString="Data Source=somerserver.xx\SQLEXPRESS;Initial Catalog=bedriftsmelding;User Id=SomeUser;Password=SomePassword;Integrated Security=False" providerName="System.Data.SqlClient" />
堆栈跟踪:
System.NotSupportedException未由用户代码处理
Message =不支持指定的方法.
源= System.Web.Extensions StackTrace: 在System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider.GetAllUsers(Int32 pageIndex,Int32 pageSize,Int32& totalRecords) 在System.Web.Security.Membership.GetAllUsers(Int32 pageIndex,Int32 pageSize,Int32& TotalRecords) 在System.Web.Security.Membership.GetAllUsers() 在Bedriftsmelding.Nettside.Models.CompanyUsers.GetUserIdFromUserName(String 用户名) C:\ Projects \ Bedriftsmelding \ Bedriftsmelding.Nettside \ Models \ CompanyUsers.cs:line 26 在Bedriftsmelding.Tests.DTO.CompanyUsersTest.TestGetUserIdFromUserName() 在 C:\ Projects \ Bedriftsmelding \ Bedriftsmelding.Tests \ DTO \ CompanyUsersTest.cs:line 16 InnerException:
System.NotSupportedException was unhandled by user code
Message=Specified method is not supported.
Source=System.Web.Extensions StackTrace: at System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords) at System.Web.Security.Membership.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords) at System.Web.Security.Membership.GetAllUsers() at Bedriftsmelding.Nettside.Models.CompanyUsers.GetUserIdFromUserName(String username) in C:\Projects\Bedriftsmelding\Bedriftsmelding.Nettside\Models\CompanyUsers.cs:line 26 at Bedriftsmelding.Tests.DTO.CompanyUsersTest.TestGetUserIdFromUserName() in C:\Projects\Bedriftsmelding\Bedriftsmelding.Tests\DTO\CompanyUsersTest.cs:line 16 InnerException:
推荐答案
好像您使用的是ClientFormsAuthenticationMembershipProvider,而不是默认的SqlMembershipProvider.
Looks like you're using a ClientFormsAuthenticationMembershipProvider rather than the default SqlMembershipProvider.
根据ClientFormsAuthenticationMembershipProvider的文档,不支持GetllAllUsers并抛出不支持的异常.
According to the docs for ClientFormsAuthenticationMembershipProvider, GetllAllUsers is not supported and throws a not supported exception.
似乎只有基本的ValiateUser和其他一些功能与此提供程序一起使用,因为它是为与Ajax扩展一起使用而设计的.没有一个用户函数可以正常工作,例如GetUser,GetAllUsers,DeleteUser,CreateUser等...
It appears that only the basic ValiateUser and a few other functions work with this provider, as it's designed for use with the Ajax extensions. None of the user functions work, such as GetUser, GetAllUsers, DeleteUser, CreateUser, etc...
这篇关于将Membership.GetAllUsers()转换为通用列表时出现NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!