| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
-
- ASP.NET MVC core dependencies have been added to the project.
- However you may still need to do make changes to your project.
- 1. Suggested changes to Startup class:
- 1.1 Add a constructor:
- public IConfigurationRoot Configuration { get; }
- public Startup(IHostingEnvironment env)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
- .AddEnvironmentVariables();
- Configuration = builder.Build();
- }
- 1.2 Add MVC services:
- public void ConfigureServices(IServiceCollection services)
- {
- // Add framework services.
- services.AddMvc();
- }
- 1.3 Configure web app to use use Configuration and use MVC routing:
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- loggerFactory.AddConsole(Configuration.GetSection("Logging"));
- loggerFactory.AddDebug();
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- }
- app.UseStaticFiles();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- }
|