Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Authorize dynamically roles for Controller API in ASP.NET 5 (1.0.0-beta7)

$
0
0

Hi,

I am developing Authorization function for a Web API project in ASP.NET 5.

Currently I have configured Roles for Controller statically using [Authorize(Roles = "Admin")] as below:

[Authorize(Roles = "Admin")]
[Route("api/[controller]")]
public class ValuesController : Controller
{
    // GET: api/values
    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
}

"Admin" role is hard code for Controller. 

But in fact, all roles will be stored in DB and I want to load and set them for Controllers/Methods in Controller when App start at runtime

If anybody know how to do this ? Please help.

Thanks in advance.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>