Startup.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Logging;
  12. using Winsoft.GOV.XF.WXCore.Data;
  13. using Winsoft.GOV.XF.WXCore.Models;
  14. using Winsoft.GOV.XF.WXCore.Services;
  15. namespace Winsoft.GOV.XF.WXCore
  16. {
  17. public class Startup
  18. {
  19. public Startup(IHostingEnvironment env)
  20. {
  21. var builder = new ConfigurationBuilder()
  22. .SetBasePath(env.ContentRootPath)
  23. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  24. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  25. if (env.IsDevelopment())
  26. {
  27. // For more details on using the user secret store see https://go.microsoft.com/fwlink/?LinkID=532709
  28. builder.AddUserSecrets<Startup>();
  29. }
  30. builder.AddEnvironmentVariables();
  31. Configuration = builder.Build();
  32. }
  33. public IConfigurationRoot Configuration { get; }
  34. // This method gets called by the runtime. Use this method to add services to the container.
  35. public void ConfigureServices(IServiceCollection services)
  36. {
  37. // Add framework services.
  38. services.AddDbContext<ApplicationDbContext>(options =>
  39. options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  40. services.AddIdentity<ApplicationUser, IdentityRole>()
  41. .AddEntityFrameworkStores<ApplicationDbContext>()
  42. .AddDefaultTokenProviders();
  43. services.AddMvc();
  44. // Add application services.
  45. services.AddTransient<IEmailSender, AuthMessageSender>();
  46. services.AddTransient<ISmsSender, AuthMessageSender>();
  47. }
  48. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  49. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  50. {
  51. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  52. loggerFactory.AddDebug();
  53. if (env.IsDevelopment())
  54. {
  55. app.UseDeveloperExceptionPage();
  56. app.UseDatabaseErrorPage();
  57. app.UseBrowserLink();
  58. }
  59. else
  60. {
  61. app.UseExceptionHandler("/Home/Error");
  62. }
  63. app.UseStaticFiles();
  64. app.UseIdentity();
  65. // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715
  66. app.UseMvc(routes =>
  67. {
  68. routes.MapRoute(
  69. name: "default",
  70. template: "{controller=Home}/{action=Index}/{id?}");
  71. });
  72. }
  73. }
  74. }