简体   繁体   中英

Another database for login in asp.net mvc

I want to add roles to my website in asp.net mvc 3 so that only an specific role can look at certain controllers.

I read the music store tutorial, and went to the asp .net web administration tool and read that I can customize my provider in the provider tab.

I have in a table called Client from my database and it has columns "Username" "Password" etc. I want to check the login info in these tables.

I went to the provider tab and I can only see AspNetSqlProvider I cannot see a way to add my database there or anything...(the database is already in my project)

How can I configure this. I've search online but haven't found how. Could anyone point me in the direction to do this?

Microsoft developed a much simpler membership provider called SimpleMembership , that allows you to very easily use an existing database and specify where your usernames/passwords are stored. It was originally introduced for use with the ASP.NET WebPages framework, in WebMatrix, but there already exists a NuGet package that allows you to use it with ASP.NET MVC:

webSecurityService.InitializeDatabaseConnection(
    connectionStringName: "Default", 
    userTableName: "Users", 
    userIdColumn: "ID", 
    userNameColumn: "Username", 
    autoCreateTables: true);

SimpleMembership.Mvc3 NuGet Package

You will need to implement a custom membership provider that knows how to check your custom database schema. Here is a video that might get you started. There are heaps of resources online too now that you know the correct terminology to search for ;)

Have a look at Universal Membership Provider Works with SQL Express, Compact, and Azure. Just give it a connection string to your membership DB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM