Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created April 14, 2021 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/ec7135feabd61c7e47728a70d205849f to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/ec7135feabd61c7e47728a70d205849f to your computer and use it in GitHub Desktop.
Inject IConfiguration in controller to read the configuration value.
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IConfiguration configuration;
public HomeController(ILogger<HomeController> logger, IConfiguration configuration)
{
_logger = logger;
this.configuration = configuration;
}
public IActionResult Index()
{
ViewData["Mode"] = configuration["Mode"];
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment