How to allow multiple authentication methods in ASP.NET?

前端 未结 3 1808
甜味超标
甜味超标 2020-12-23 12:11

I\'m building a new ASP.NET MVC application (in C#) and one of the requirements is to create a new database of members. For this, we\'d need roles to manage the different ty

3条回答
  •  轮回少年
    2020-12-23 12:50

    One idea we've followed is to create a custom Membership / Role / Profile provider. We customised the login / authentication methods significantly and have an additional table of logins. This table basically just contained:

    LoginID (Auto-Incremental ID, PK)
    UserID (FK)
    LoginSystemID (FK)
    ...blah blah
    

    Within the above, the LoginSystemID was a link to a foreign lookup table which helped the system to determine which authentication service to use (e.g. Standard, AD, OpenID, FacebookConnect - etc).

    The problem we ran into was that the Username field in the MembershipProvider couldn't be empty and while in our schema everyone had a UserID (it was their account name), they didn't have a Username that was unique. We had to get around this by generating a GUID and using that. This of course is hidden from the user and a DisplayName attribute from our Users table can be displayed instead.

    This was all done via FormsAuthenication (the AD checks were done via LDAP checks). However, an additional layer (a webform) was added with appropriate settings within IIS that provided a means for automatic WindowsAuthentication - we redirect to there in the instance that we feel the user is likely to be internal (based on IP address).

提交回复
热议问题