试图访问ASPNETDB.MDF数据库文件以获取用户信息.ASP.NET MVC [英] Trying to access the ASPNETDB.MDF database file to get user information.. ASP.NET MVC

查看:110
本文介绍了试图访问ASPNETDB.MDF数据库文件以获取用户信息.ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...我正在尝试访问ASPNETDB.MDF文件中包含的用户信息.我正在使用ASP.NET MVC.从Visual Studio启动ASP.NET配置工具时,将创建此文件.因此,我通过此ASP.NET配置工具创建了用户,角色等,并将数据保存到此数据库文件中.

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.

我需要访问要在我的应用程序中使用的用户信息(仅是用户名).例如,我想要做的是用用户名列表填充一个下拉列表(用户名是通过ASP.NET配置工具创建的,因此位于此ASPNETDB数据库文件中).我认为,如果我能弄清楚如何获得这些信息,那么我就可以弄清楚其余的信息.

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.

有人会建议我做其他事情吗?我可以在主数据库中创建一个单独的用户表,但是我宁愿使用已经创建的ASPNETDB数据库中的一个用户表,只是我只使用一个源来提供用户信息,而不是两个.

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.

推荐答案

您可以使用 Membership.GetUser() 方法以 MembershipUser . 您还可以使用以下LINQ查询来获取用户名列表

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

这篇关于试图访问ASPNETDB.MDF数据库文件以获取用户信息.ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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