Trying to access the ASPNETDB.MDF database file to get user information.. ASP.NET MVC

蹲街弑〆低调 提交于 2019-12-13 05:41:40

问题


Hey everyone... I'm trying to access user information that's contained within the ASPNETDB.MDF file. I'm using ASP.NET MVC. This file gets created when you launch the ASP.NET Configuration tool from Visual Studio. So, I create users, roles, etc. via this ASP.NET Configuration tool, and the data gets saved to this database file.

I'm needing to gain access to user information (just the user name) to use within my application. For example, what I'm trying to do is populate a drop down list with a list of user names (which were created from the ASP.NET Configuration tool, and therefore reside within this ASPNETDB database file). I think if I can figure out how to get that information then I can figure out the rest.

Is there any other way someone would suggest me going about this? I could create a separate users table in my main database, but I would rather use the one in the ASPNETDB database that's already created, just so I use one source for my user's information and not two.


回答1:


You can use Membership.GetUser() method to get all users in the database as a MembershipUser. You can also use following LINQ Query to get a list of user names

 var users = from user in Membership.GetUsers() 
                 orderby user.UserName 
                 select user.UserName


来源:https://stackoverflow.com/questions/4720472/trying-to-access-the-aspnetdb-mdf-database-file-to-get-user-information-asp-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!