// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { //配置连接字符串 ZHYYDBSqlServerHIS.Startup s = new ZHYYDBSqlServerHIS.Startup(this.Configuration); s.ConfigureServices(services); //另外在服务中Services01中 要引用IdentityServer4.AccessTokenValidation var idResources = new List <IdentityResource> { new IdentityResources.OpenId(),//必须添加,否则报无效scope错误 new IdentityResources.Profile() }; ////获取DB数据库中的数据 //IEnumerable<Users> userlist = new List<Users>(); ////带scope ////var scope = services.BuildServiceProvider().CreateScope(); ////DB context = scope.ServiceProvider.GetRequiredService<DB>(); //// userlist = context.Users; //不带scope DB context = services.BuildServiceProvider().GetRequiredService <DB>(); this.SqlSX(context); //鉴权中心 services.AddIdentityServer() .AddDeveloperSigningCredential() .AddResourceOwnerValidator <ValiedUser>() .AddInMemoryApiResources(Config.GetApiResources()) .AddInMemoryClients(Config.GetClients(context.Users)); //.AddInMemoryIdentityResources(idResources) //.AddProfileService<Profile>(); services.AddMvcCore(); services.AddControllersWithViews(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ZHYYDBSqlServerHIS.Startup s = new ZHYYDBSqlServerHIS.Startup(Configuration); s.ConfigureServices(services); services.AddMvcCore(); services.AddControllersWithViews(); //允许跨域 //允许一个或多个来源可以跨域 services.AddCors(options => { options.AddPolicy("CustomCorsPolicy", policy => { // 设定允许跨域的来源,有多个可以用','隔开 policy.WithOrigins("https://localhost:44362")//只允许https://localhost:5000来源允许跨域 .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); }