ASP.NET Membership Provider with EF

I use the ASP.NET Membership Provider as it is, and it just works great for my basic purpose. One thing that I understand is that it sets up a bunch of stored proxies, etc. To the database.

Is there an EF implementation for ASP.NET membership? or will it be?

I have an upcoming project that I will need to expand the functionality of membership providers with roles and authorization through some GUI.

In addition, every time I use this, I have two connection lines in my web.config file for DbContext one for application services, especially for the membership provider. Why don't I have only one?

+7
source share
3 answers

There are gui membership management systems for MVC3 that you can view or add to your project.

You can play with them and see how they work. It is simple as soon as you know where to look, and you can create your own.

Membership Class and MembershipUser Class contains all user information. For example, in order not to approve the user, you can do this:

MembershipUser user = Membership.GetUser("userName"); user.IsApproved = false; Membership.UpdateUser(user); 

And if you want to delete a user, you can use Membership.DeleteUser("userName"); .

The role class contains all the information associated with the role. For example, Roles.GetUsersInRole("roleName") will return a list of all users in the role roleName . Roles.CreateRole("roleName"); will create a role, and Roles.DeleteRole("roleName"); will delete the role.

If you need more than just the default, you can see Implementing a Membership Provider .

As for having two databases, this is optional. You can add all ASP.NET tables, stored procedures, etc. Into your database using the Aspnet_regsql tool. See Installing a database using Aspnet_regsql.exe . This will allow you to have only one database, so you can delete the asp.net connection string in your Web.Config and then change the AspNetSqlMembershipProvider AspNetSqlProfileProvider AspNetSqlRoleProvider and possibly others to use the connection string to your main database.

0
source

Generic providers are what you are looking for: http://nuget.org/packages/Microsoft.AspNet.Providers.Core

They are implemented using EF Code First 5 inside, we will open the internal DBContexts as soon as we make sure that everything works smoothly.

+2
source

For an ASP.NET membership provider and role implementation in the Entity Framework, you must import all ASPNETDB views (membership databases) in an EDMX file. e.g. vw_aspnet_MembershipUsers, vw_aspnet_Roles, vw_aspnet_UsersInRoles, vw_aspnet_Users, etc.

Membership will then be done through EF. In this way, you can provide a graphical interface using the following functions.

here is the controller code. eg.

  // GET: /Membership/Edit/5 public ActionResult Edit(Guid id) { var recordToEdit = (from r in _db.vw_aspnet_Users where r.UserId == id select r).First(); return View(recordToEdit); } public ActionResult Index() { return View(_db.vw_aspnet_MembershipUsers.ToList()); } 

Now, how to combine ASPNETDB with an existing database, make only one connection string in web.config. (Your question: why don't I have only one?)

It is also possible using the following steps.

ASPNETDB.MDF is a membership provider database and is used to store and retrieve membership data from a database, and here we will see how to create a membership provider database. The command used to create Aspnetdb.mdf is ASPNET_RegSQL.EXE

1.Start-> Programs-> Microsoft visual studio 2005-> visual studio tools-> Visual Studio 2005 Command Prompt. Enter ASPNET_RegSQL.EXE at the Visual Studio command prompt

  • A wizard will be displayed with the heading "Welcome to the Spl Asp.Net Server Wizard." Here you need to click "Next"

  • Next, a wizard appears with the option "Select a setting". Now we need to select the "Configure SQL Server for Application Defaults" setting option. Choose the one you want and then.

  • A window with "Select Sql Server Database" will be displayed. Now we need to select our SQL server database. Here you need to install the server, authentication type and database. If you select the default name "aspnetDb.mdf", it will be selected. If you want to modify an existing database, select this database.

5. A confirmation message with the heading “Confirm Settings” will now be displayed. Now check the server name and database name and click Next.

  • A window appears with "Database Created or Modified." Now click Finish

Be careful in the above steps, you need to select an existing database. Some tables (11+), views, stored membership procedures and roles will be added to your existing database ....

Enjoy ... Thanks ...

0
source

All Articles