I am new to MVC5. Please help.
Following is the Controller class decorated with <authorize> Attribute.
The Authorize Attribute is at Class level and at Action level too.
I want to access Users and Roles in the Controller and Action, it belongs to.
How to write the [Magic Code] for this?
I am trying to have Authorization and Authentication with built-in MVC Authorize.
I want to use Database for Authentication.
My plan is to write my own code in Action Method for Authorization and Authentication or give a call to generic function.
<Authorize(Users:="User1,User3", Roles:="Role1"Role2")>
Public Class AbcController : Inherits Controller
.
.
.
<Authorize(Users:="User2,User4"), Roles:="Role3,Role4">
Public Function XyzAction() As ActionResult
.
.
.
dim s1, s2, s3, s4 as String
' The Magic Code here...
' THEN, values of S1 to s4 are expected as:
s1 => "User2,User4"
s2 => "Role1,Role2"
s3 => "User2,User4" and
s4 => "Role3,Role4"
.
.
.
End Function
.
.
.
End Class
What I have tried:
I tried too many things including:
Overriding method OnAuthorization
Using Roles.GetRolesForUser(User.Identity.Name)
Read many articales but not found any of use.
Many times thought, Is it possible?