Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the ASP.NET membership provider database with your own database?

We are developing an ASP.NET MVC Application that currently uses it's own database ApplicationData for the domain models and another one Membership for the user management / membership provider.

We do access restrictions using data-annotations in our controllers.

[Authorize(Roles = "administrators, managers")]

This worked great for simple use cases.


As we are scaling our application our customer wants to restrict specific users to access specific areas of our ApplicationData database.

Each of our products contains a foreign key referring to the region the product was assembled in.

A user story would be:

  • Users in the role NewYorkManagers should only be able to edit / see products that are assembled in New York.

We created a placeholder table UserRightsRegions that contains the UserId and the RegionId.

How can I link both the ApplicationData and the Membership databases in order to work properly / having cross-database-key-references? (Is something like this even possible?)

All help is more than appreciated!

like image 588
Faizan S. Avatar asked Mar 10 '10 15:03

Faizan S.


People also ask

How can I use ASP.NET Membership provider?

The ASP.NET membership provider is a feature that enables ASP.NET developers to create Web sites that allow users to create unique user name and password combinations. With this facility, any user can establish an account with the site, and sign in for exclusive access to the site and its services.

How can I use ASP.NET Membership in C#?

To create a user in our application by using ASP.NET Membership we need the following steps to complete this process. Step 1: Firstly, open visual studio, then go to File Menu and click New -> Web Site. Step 2: After open the new empty website and add a new item Login. aspx in Registration inside Solution Explorer.

What is SQL Membership Provider?

SQLMembershipProvider : It is used to store user information in a SQL Server database. ActiveDirectoryMembershipProvider : It is used to store user information in an Active Directory.


1 Answers

In my opinion, you should be able to integrate your database with the standard aspnet_db reliably, but I would advise against duplicating or replacing the aspnet_users table.

That is the focal point of all the providers that use the aspnet_db schema, including custom providers that may augment but do not implement custom replacement.

To maximize reuse of strong tested infrastructure code in the provider stack/API it is best to go with that flow.

You will want to be very attentive to any modified membership core functions and ensure that the way your new constraints behave in an expected fashion in each case.

The facet of the membership story that I have found needs the most attention is deleting a user, and a simple modification/addition to the delete user sproc can manage this capably.

like image 197
Sky Sanders Avatar answered Oct 20 '22 20:10

Sky Sanders