开发者

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,开发者_如何学JAVA 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜