Sheol
Sheol

Reputation: 164

ASP.net Windows Authentication with custom database

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!

Upvotes: 2

Views: 1390

Answers (1)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93454

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?

Upvotes: 2

Related Questions