Startup.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using AuthorizeCenter.AuthConfig;
  2. using AuthorizeCenter.Services;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.Extensions.DependencyInjection;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace AuthorizeCenter
  13. {
  14. public class Startup
  15. {
  16. // This method gets called by the runtime. Use this method to add services to the container.
  17. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
  18. public void ConfigureServices(IServiceCollection services)
  19. {
  20. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  21. services.AddIdentityServer() //Ids4服务
  22. .AddDeveloperSigningCredential()
  23. .AddInMemoryIdentityResources(Config.GetIdentityResources())
  24. .AddInMemoryClients(Config.GetClients());//把配置文件的Client配置资源放到内存
  25. services.AddTransient<AccountService>();
  26. }
  27. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  28. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  29. {
  30. if (env.IsDevelopment())
  31. {
  32. app.UseDeveloperExceptionPage();
  33. }
  34. app.UseHttpsRedirection();
  35. app.UseStaticFiles();
  36. app.UseCookiePolicy();
  37. app.UseIdentityServer();
  38. app.UseMvc(routes =>
  39. {
  40. routes.MapRoute(
  41. name: "default",
  42. template: "{controller=Home}/{action=Index}/{id?}");
  43. });
  44. }
  45. }
  46. }