简体   繁体   中英

ASP.NET MVC 5 Adding roles to an existing application w. Forms authentication (C#)

situation is as follows: I have an existing MVC 5 application and created some very, very basic log-in functionality for it. I just have a table for users and passwords in my database, and use forms authentication to check if a user exists (and some actions can only be done if you are logged in).

Now I would like to extend the authentication system to use roles. From what I gather, I need to make a table in the database with roles, and of course give users a field that contains their role.

But I don't know how I could then use that information in my MVC application for authentication (using that nice [Authorize(Roles="admin")] syntax). All the examples i found for using the identity system use the template site, which I did not use to create this app (I started from an empty project).

根据我的理解,我认为您可以使用User.IsInRole()方法或AuthorizeAttribute来验证特定角色中的用户,而不是 Membership 方法或身份方法。

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