2

I'm creating an intranet website that requires Windows Authentication. I already set up everything, or I think I did, to use windows authentication and roles managed in a database. That's important because I can't use the Active Directory groups and roles.

It works. When I enter the website it display my Windows user name and it is accesible with User.Identity.Name. I can validate a role using User.IsInRole("roleName") and it works too.

Now the problem I have is that when I use Membership.GetUser and Membership.GetAllUsers I always get null and an empty collection.

My RoleManager Provider is:

<add 
name="SqlRoleManager" 
type="System.Web.Security.SqlRoleProvider" 
connectionStringName="ApplicationServices" 
applicationName="/appName" 
/>

And my Membership Provider is this one:

<add 
name="AspNetSqlMembershipProvider" 
type="System.Web.Security.SqlMembershipProvider" 
connectionStringName="ApplicationServices" 
applicationName="/appName" 
/>

Am I missing something or my config is wrong? Thanks!

6
  • Have you set the default membership provider? Commented Oct 22, 2012 at 15:39
  • And I believe there is one / too much inside application name Commented Oct 22, 2012 at 15:40
  • Check this link for more details: msdn.microsoft.com/en-us/library/… Commented Oct 22, 2012 at 15:41
  • Hi. How I do set the defualt provider? Commented Oct 22, 2012 at 15:41
  • Inside web config <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> Check the link I have posted! Commented Oct 22, 2012 at 15:49

1 Answer 1

2

Why do you want to call Membership.GetUser? You are already authenticated via Windows Authentication. If you want to use Membership with Windows Authentication (why, i don't know), you have to jump through some more hoops.

You can use the ActiveDirectoryMembershipProvider, rather than SqlMembershipProvider. This lets you call GetUser and retrieve AD information.

You can copy the Windows Authentication information into a SqlMembership database on login.

You can create a custom membership provider that allows you to do all the authentication yourself.

So, the first question is why do you want to use Membership?

Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks for the answer. I don't use ActiveDirectoryMembershipProvider because, as far I understand, it is for using Active Directory groups which I don't need and I can't modify. About using Membership I know I already managed to login with windows authentication, but I want to use Membership.GetUser to get the UserId of the current user, thing I can't do with User.Identity or IPrincipal. Right now I get the UserId with an extra query to the database using the user name, but it just look wrong as Membership is supposed to help with those methods.
What do you mean with copying Windows Auth. information into the database? About creating a custom membership... well I have no idea about how to create a new one and still using Windows Auth. With that I mean just displaying the current Windows user without asking any password nor having to manage it.
@Sheol - No. ActiveDirectoryMembershipProvider is about authentication only. You use the WindowsTokenRoleProvider to provide the AD groups from AD. If you are using SqlRoleProvider and ActiveDirectoryMembershipProvider then it will do what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.