using asp.net membership api when I call Roles.GetRolesForUser(); it returns nothing. When I make a call Roles.GetAllRoles() all the roles are returned. What is the problem? Also what is the correct way to authenticate users using the membership开发者_如何学JAVA api?
Roles.GetRolesForUser() returns the roles for currently logged-in user.
1: make sure you are executing it when you are logged-in.
2: Make sure that user is assigned a role.
For your question about best way I am not sure in what context you are asking. But basically if you are using built-in ASP.NET Login control you don't have to do anything. You can use Membership.ValidateUser method explicitly if you want to. One key thing to note is you do need FormsAuthentication set in your web.config.
Have you hosted using IIS and done Anonymous Authentication? Typically any security provider will use the easiest one it finds.
It would start with Anonymous then if it's disabled then it would look for Forms, then Windows.
The cassini web server built into Visual Studio would do this for you.
You need to add [InitializeSimpleMembership] before the cont in the controller
精彩评论