将Membership.GetAllUsers()转换为通用列表时出现NotSupportedException [英] NotSupportedException when casting Membership.GetAllUsers() to generic list

查看:107
本文介绍了将Membership.GetAllUsers()转换为通用列表时出现NotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在获取所有用户名时,我尝试在.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.

http://msdn. microsoft.com/en-us/library/system.web.clientservices.providers.clientformsauthenticationmembershipprovider.getallusers.aspx

似乎只有基本的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆