2012-08-08 5 views
0

사용자 계정 목록을 검색하려면 멤버십 데이터베이스에 어떻게 연결합니까? 예를 들어 내 프로필에 연결할 수 있습니다.MVC 회원 데이터베이스 컨텍스트?

Private db As UserProfileDbContext = New UserProfileDbContext 

    ' 
    ' GET: /UserProfile/ 

    Function Index() As ViewResult 
     Return View(db.UserProfiles.ToList()) 
    End Function 

계정 모델에 지정된 사용자 계정 데이터베이스 컨텍스트가없는 것 같습니다. 하나를 만들거나 위와 같은 목록으로 모든 사용자 계정을 검색하는 더 좋은 방법이 있습니까?

편집 :

나는 컨트롤러에서이 코드를 가지고 :

' 
' GET: /Account/ViewRegistries 

Function ViewRegistries() As ViewResult 
    Return View(Membership.GetAllUsers().Cast(Of MembershipUser).ToList) 
End Function 

내보기 :

The model item passed into the dictionary is of type 'System.Collections.Generic.List 1[System.Web.Security.MembershipUser]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable 1[MyBlog.RegisterModel]'.

어떻게 :하지만 오류가 발생

@ModelType IEnumerable(Of MyBlog.RegisterModel) 

@Code 
    ViewData("Title") = "Index" 
End Code 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      UserId 
     </th> 
     <th> 
      CompanyId 
     </th> 
     <th></th> 
    </tr> 

@For Each item In Model 
    Dim currentItem = item 
    @<tr> 
     <td> 
      @Html.DisplayFor(Function(modelItem) currentItem.UserName) 
     </td> 
     <td> 
      @Html.DisplayFor(Function(modelItem) currentItem.Company) 
     </td> 
    </tr> 
Next 

</table> 

고쳐? 사용자를 등록하면이 데이터베이스에있는 모든 사용자의 목록을 반환합니다

Membership.GetAllUsers() 

:

+1

그냥 만들거나 로그인하여 로그인하고 거기에 등록하십시오. 사용자가 없으므로 처음에는 아무 것도 사용하지 않습니다. 만들어야합니다. – Rajesh

+0

또한 비주얼 스튜디오에서 aspnet 구성을 사용하여 만들 수 있습니다. 또는 Visual Studio 명령 프롬프트에서 aspnet_regsql.exe를 사용할 수 있습니다. – Rajesh

+1

@Rajesh : 서버에 게시 할 때 여전히 aspnet 구성을 사용할 수 있습니까? 암호로 보호 된 것으로 보이지 않습니다. – user1477388

답변

2

당신은 멤버 자격 공급자를 사용할 수 있습니다.

+0

예. 대린 말이 맞아. 그러나 연결 문자열이 맞는지 확인하십시오. 그런 다음 데이터베이스의 일부 사용자를 등록하십시오. – Rajesh

+0

이것이 내 모델로 들어가 db.UserProfiles.ToList()와 같은 방식으로 사용됩니까? 아니면 더 많은 일을해야합니까? – user1477388

+1

이렇게하면 멤버 자격 공급자에게 쿼리하고 'MembershipUser' 목록을 반환합니다. 사용자 이름 목록을 가져 오려면 LINQ :'Dim usernames = Membership.GetAllUsers(). 캐스트 (Of MembershipUser) .Select (Function (u) u.UserName) .ToList()'를 사용하십시오. –

관련 문제