You must Sign In to post a response.
  • Category: ASP.Net MVC

    Read values from config in [Authorize(Roles = "config value"] in MVC.Controller

    how to Read values from config in [Authorize(Roles = "config value"] in MVC.Controller
  • #768742
    Hai Sid,
    First of all you need to get the class name and then you can iterate through the Attribute name with its value.
    e.g.

    var propertyName = typeof(ClassName).GetProperty(s);
    var displayAttribute= propertyName.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute;
    if(displayAttribute!= null)
    {
    var name = displayAttribute.Name;
    }

    You can also follow the below link for more details:

    http://stackoverflow.com/questions/14309255/mvc-access-display-name-attribute-in-the-controller

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768746
    namespace GP..Viewer.Controllers
    {
    [Authorize(Roles = ConfigurationManager.AppSettings["ViewerRole"])]
    public class ViewerController : Controller
    {
    ....

    => How do I read ViewerRole value in above code from config


Sign In to post your comments