Advertisement
Guest User

Untitled

a guest
Aug 26th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. namespace MediaCenter
  2. {
  3. public class Startup
  4. {
  5. public Startup(IHostingEnvironment env)
  6. {
  7. var builder = new ConfigurationBuilder()
  8. .SetBasePath(env.ContentRootPath)
  9. .AddEnvironmentVariables()
  10. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  11. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  12.  
  13. // Set the new Configuration
  14. Configuration = builder.Build();
  15. }
  16.  
  17. public IConfiguration Configuration { get; set; }
  18.  
  19. // This method gets called by the runtime. Use this method to add services to the container.
  20. public void ConfigureServices(IServiceCollection services)
  21. {
  22. services.AddMvc()
  23. .AddJsonOptions(config =>
  24. {
  25. config.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
  26. });
  27. services.AddOptions();
  28. services.AddSingleton<IConfiguration>(Configuration);
  29.  
  30.  
  31. }
  32.  
  33. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  34. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  35. {
  36. if (env.IsDevelopment())
  37. {
  38. app.UseBrowserLink();
  39. app.UseDeveloperExceptionPage();
  40.  
  41. }
  42. else
  43. {
  44. app.UseExceptionHandler("/Home/Error");
  45. }
  46.  
  47. app.UseStaticFiles();
  48.  
  49. app.UseMvc(routes =>
  50. {
  51. routes.MapRoute(
  52. name: "default",
  53. template: "{controller=Home}/{action=Index}/{id?}");
  54. });
  55.  
  56.  
  57. }
  58. }
  59. }
  60.  
  61.  
  62. my startuo.cs
  63.  
  64.  
  65. namespace MediaCenter.Controllers
  66. {
  67. public class HomeController : Controller
  68. {
  69. private IConfiguration _configuration;
  70.  
  71. public HomeController(IConfiguration configuration)
  72. {
  73. _configuration = configuration;
  74. }
  75.  
  76. public IActionResult Index()
  77. {
  78. return View();
  79. }
  80.  
  81. public IActionResult Settings()
  82. {
  83.  
  84. var array =_configuration.GetSection("Locations:Location").GetChildren()
  85. .Select(configsection => configsection.Value);
  86.  
  87.  
  88. return View();
  89. }
  90.  
  91. }
  92. }
  93.  
  94.  
  95. my controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement