Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MediaCenter
- {
- public class Startup
- {
- public Startup(IHostingEnvironment env)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddEnvironmentVariables()
- .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
- // Set the new Configuration
- Configuration = builder.Build();
- }
- public IConfiguration Configuration { get; set; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddMvc()
- .AddJsonOptions(config =>
- {
- config.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
- });
- services.AddOptions();
- services.AddSingleton<IConfiguration>(Configuration);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseBrowserLink();
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- }
- app.UseStaticFiles();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- }
- }
- }
- my startuo.cs
- namespace MediaCenter.Controllers
- {
- public class HomeController : Controller
- {
- private IConfiguration _configuration;
- public HomeController(IConfiguration configuration)
- {
- _configuration = configuration;
- }
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult Settings()
- {
- var array =_configuration.GetSection("Locations:Location").GetChildren()
- .Select(configsection => configsection.Value);
- return View();
- }
- }
- }
- my controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement