ScaffoldingReadMe.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 
  2. ASP.NET MVC core dependencies have been added to the project.
  3. However you may still need to do make changes to your project.
  4. 1. Suggested changes to Startup class:
  5. 1.1 Add a constructor:
  6. public IConfigurationRoot Configuration { get; }
  7. public Startup(IHostingEnvironment env)
  8. {
  9. var builder = new ConfigurationBuilder()
  10. .SetBasePath(env.ContentRootPath)
  11. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  12. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  13. .AddEnvironmentVariables();
  14. Configuration = builder.Build();
  15. }
  16. 1.2 Add MVC services:
  17. public void ConfigureServices(IServiceCollection services)
  18. {
  19. // Add framework services.
  20. services.AddMvc();
  21. }
  22. 1.3 Configure web app to use use Configuration and use MVC routing:
  23. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  24. {
  25. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  26. loggerFactory.AddDebug();
  27. if (env.IsDevelopment())
  28. {
  29. app.UseDeveloperExceptionPage();
  30. }
  31. else
  32. {
  33. app.UseExceptionHandler("/Home/Error");
  34. }
  35. app.UseStaticFiles();
  36. app.UseMvc(routes =>
  37. {
  38. routes.MapRoute(
  39. name: "default",
  40. template: "{controller=Home}/{action=Index}/{id?}");
  41. });
  42. }