0

How can I get a value from the ASP.NET MVC 5 web.config into a controller method?

At first I put the value into a string and that works:

public const string ADUser = System.Configuration.ConfigurationManager.AppSettings["ADUser"].ToString();

There are many examples on Stackoverflow with

public const string 

but in my case it doesn't work.

[Authorize(Users = ADUser)]
public ViewResult Index()
{
    var user = db.user
                 .Where(m => m.Id != 0)
                 .ToList();
            
    return View(user);
}

Here is the exception. It belong to the [Authorize(Users = ADUser)]

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type enum Description

Does anybody have any idea?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
post4dirk
  • 313
  • 4
  • 16
  • you could create your own (custom) Authorize attribute and do something like this: https://stackoverflow.com/questions/30099613/dynamically-add-roles-to-authorize-attribute-for-controller – vhr Dec 13 '22 at 13:56

0 Answers0