locked
How can I implement role based custom user authentication in asp.net code fist entity framework MVC5 RRS feed

  • Question

  • User-471420332 posted

    Using scaffolding I have two table

    1) Role

    RoleId  RoleName
     1       User
     2       Admin

    2)Registration

    Username       Password    Email              RoleId 
     Mazhar           xyz       m@gmail.com          1
     Admin            xyz       admin@gmail.com      2

    Base on email and password user and admin login and they will get there page.

    I need login controller code to achieve this. Thank you in advance

    Monday, July 30, 2018 9:33 AM

All replies

  • User753101303 posted

    Hi,

    Not sure to get it. You want to automatically add a user to the Admin role if his mail address starts with "admin@" ? Seems weird. It would allow any user with the correct criteria gain admin access to your app.

    IMO only a registered admin should be able to take this kind of decision. users is using an admin@sowhere.com mail address ???

    Else it seems a sample test and then it depends which API you are using. Try perhaps https://msdn.microsoft.com/en-us/library/dn468058(v=vs.111).aspx

    Edit: or maybe with an additional check so that it can happen only if not other user has admin access ???

    Monday, July 30, 2018 11:19 AM
  • Monday, July 30, 2018 11:48 AM
  • User-471420332 posted

    Dear Mudasarkhan,

    As you given link, that is not related to code first, i  think its database first approach?

    Monday, July 30, 2018 11:52 AM
  • User-1171043462 posted

    Yes. It is Database First.

    Monday, July 30, 2018 12:24 PM
  • User-471420332 posted

    I asked for code first mudassar.

    Monday, July 30, 2018 12:46 PM
  • User-1171043462 posted

    There is no ready example for Code- first.

    You can implement your Code First approach and then follow the Forms Authentication and Role Based Security explained in the article.

    Monday, July 30, 2018 12:49 PM