/// <summary> /// 添加FileService.Sdk.Server的相关服务 /// </summary> public static void AddFileService(this IServiceCollection services) { ServiceConfigure.AddAuthorization(services); services.AddSingleton <IFileServiceManager, FileServiceManager>(); services.AddSingleton <IHttpClientFactory, DefaultHttpClientFactory>(); services.Configure <HttpClientFactoryOptions>(opt => { }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddControllers(); services.AddRazorPages(); services.AddMvc() .AddRazorPagesOptions(options => { options.Conventions.AddPageRoute("/Search/Index", ""); }) .AddNewtonsoftJson(); ServiceConfigure.RegisterService(services); services.Configure <IdentityOptions>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; options.Password.RequiredLength = 6; options.Password.RequiredUniqueChars = 1; // Lockout settings. options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.AllowedForNewUsers = true; // User settings. options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; options.User.RequireUniqueEmail = false; }); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(5); options.LoginPath = "/Login/Index"; options.AccessDeniedPath = "/Identity/403/Denied"; options.SlidingExpiration = true; }); }
static void Main(string[] args) { try { ServiceConfigure <SampleService> .Run(null, new ServiceOption { ServiceName = "WindowsSessionZeroSample", StartPattern = ServiceStartPattern.Manually }); } catch (Exception ex) { Console.WriteLine(ex); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider svp) { try { Log.Info(this, "Inicializando Configure"); // Porque no carga el Assembly var a = new MapGq_accesos(); //Para que podamos usar el HTTPContext System.Web.HttpContext.ServiceProvider = svp; loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddDebug(); Log.Info(this, "************************************ Migrator ****************************************"); GQService.com.gq.service.Migrator.Configure(Configuration.GetSection("ConnectionDB")); GQService.com.gq.service.Migrator.Start(MigratorConfig.GetAssembly()); Log.Info(this, "************************************ Migrator ****************************************"); Log.Info(this, "************************************ ServiceConfigure ****************************************"); ServiceConfigure.Configure(MigratorConfig.GetAssembly(), MySQLConfiguration.Standard .QuerySubstitutions("1 true, 0 false") .ConnectionString(Configuration.GetSection("ConnectionDB").GetSection("ConnectionString").Value) .Driver <NHibernate.Driver.MySqlDataDriver>()); Log.Info(this, "************************************ ServiceConfigure ****************************************"); Log.Info(this, "************************************ DtoConfiguration ****************************************"); DtoConfiguration.Configure(); Log.Info(this, "************************************ DtoConfiguration ****************************************"); Log.Info(this, "************************************ SecurityConfigure ****************************************"); GQService.com.gq.security.SecurityConfigure.Configure(TimeSpan.FromSeconds(100), Security.hasPermission, new Type[] { typeof(LoginController), typeof(LocksessionController) }); Security.CreateAccessSecurity(); Log.Info(this, "************************************ SecurityConfigure ****************************************"); //IDIOMA // REVISAR https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("en-AU"), new CultureInfo("en-GB"), new CultureInfo("en"), new CultureInfo("es-ES"), new CultureInfo("es-MX"), new CultureInfo("es"), }; var requestLocalizationOptions = new RequestLocalizationOptions { RequestCultureProviders = { new CookieRequestCultureProvider() }, DefaultRequestCulture = new RequestCulture("es"), // Formatting numbers, dates, etc. SupportedCultures = supportedCultures, // UI strings that we have localized. SupportedUICultures = supportedCultures }; app.UseRequestLocalization(requestLocalizationOptions); //app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } //app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); //Indicamos que vamos a usas sesioens //app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}" ); }); } catch (Exception e) { Log.Error(this, "ERROR Configure", e); } finally { Log.Info(this, "Finalizando Configure"); } }
public void ConfigureServices(IServiceCollection services) { ServiceConfigure.AddAuthorization(services, opt => { opt.AppSecret = _cfg["General:AppSecret"]; }); services.AddSingleton <IFileTokenCodec, FileTokenCodec>(); services.AddSingleton <IMimeProvider, MimeProvider>(); services.AddSingleton <ImageSizeProvider>(); services.AddSingleton <RawFileHandler>(); services.AddSingleton <ImageFileHandler>(); services.AddSingleton(svces => new FileHandlerManager(svces)); //注册内部服务 services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //选项 services.AddOptions(); services.Configure <ServerOption>(_cfg.GetSection("Server")); services.Configure <GeneralOption>(_cfg.GetSection("General")); services.Configure <ImageConverterOption>(_cfg.GetSection("ImageConverter")); services.Configure <DbOption>(_cfg.GetSection("Db")); services.Configure <ManageOption>(_cfg.GetSection("Manage")); services.Configure <ClusterOption>(_cfg.GetSection("Cluster")); #region UEditor services.AddSingleton <UEditorOption>(); #endregion services.AddMvc(opt => { opt.Filters.Add <ValidateModelAttribute>(); }).AddJsonOptions(opt => { var setts = opt.SerializerSettings; setts.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local; setts.DateFormatHandling = DateFormatHandling.IsoDateFormat; setts.DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ssK"; }); services.AddCors(opt => { opt.AddPolicy("AllowAny", b => b.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials()); }); if (_env.IsDevelopment()) { services.AddSwaggerService(PlatformServices.Default.Application.ApplicationBasePath); } //确保服务依赖的正确性,放到所有注册服务代码后调用 if (_env.IsDevelopment()) { services.AddAutoReview( new DependencyInjectionAssert() { IgnoreTypes = new[] { "Microsoft.AspNetCore.Mvc.Razor.Internal.TagHelperComponentManager", "Microsoft.Extensions.DependencyInjection.IServiceScopeFactory", "Lwzx.Mengchu.Service.ServiceManager" } } ); } #if DEBUG_ var serviceList = services.Dump(); System.Diagnostics.Debugger.Break(); #endif }
public void ConfigureServices(IServiceCollection services) { //services.AddControllers(); ServiceConfigure.AddAuthorization(services, opt => { opt.AppSecret = _cfg["General:AppSecret"]; }); services.AddSingleton <IFileTokenCodec, FileTokenCodec>(); services.AddSingleton <IMimeProvider, MimeProvider>(); services.AddSingleton <ImageSizeProvider>(); services.AddSingleton <RawFileHandler>(); services.AddSingleton <ImageFileHandler>(); services.AddSingleton(svces => new FileHandlerManager(svces)); //注册内部服务 services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //选项 services.AddOptions(); services.Configure <ServerOption>(_cfg.GetSection("Server")); services.Configure <GeneralOption>(_cfg.GetSection("General")); services.Configure <ImageConverterOption>(_cfg.GetSection("ImageConverter")); services.Configure <DbOption>(_cfg.GetSection("Db")); services.Configure <ManageOption>(_cfg.GetSection("Manage")); services.Configure <ClusterOption>(_cfg.GetSection("Cluster")); #region UEditor services.AddSingleton <UEditorOption>(); #endregion services.AddMvc(opt => { opt.Filters.Add <ValidateModelAttribute>(); }).AddJsonOptions(opt => { var setts = opt.SerializerSettings; setts.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local; setts.DateFormatHandling = DateFormatHandling.IsoDateFormat; setts.DateFormatString = "yyyy'-'MM'-'dd'T'HH':'mm':'ssK"; }); services.AddCors(opt => { opt.AddPolicy("AllowAny", b => b.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials()); }); //if (_env.IsDevelopment()) //services.AddSwaggerService(PlatformServices.Default.Application.ApplicationBasePath); services.AddSwaggerService(PlatformServices.Default.Application.ApplicationBasePath); #region Authorize 基于策略的授权 services.AddAuthorization(options => { options.AddPolicy("Client", policy => policy.RequireRole("Client").Build()); options.AddPolicy("Admin", policy => policy.RequireRole("Admin").Build()); options.AddPolicy("SystemOrAdmin", policy => policy.RequireRole("Admin", "System")); }); //==================================== //读取配置文件 var symmetricKeyAsBase64 = _cfg["Audience:Secret"]; var keyByteArray = Encoding.ASCII.GetBytes(symmetricKeyAsBase64); var signingKey = new SymmetricSecurityKey(keyByteArray); //2.1【认证】 services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(o => { o.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = signingKey, ValidateIssuer = true, ValidIssuer = _cfg["Audience:Issuer"], //发行人 ValidateAudience = true, ValidAudience = _cfg["Audience:Audience"], //订阅人 ValidateLifetime = true, ClockSkew = TimeSpan.Zero, RequireExpirationTime = true, }; }); #endregion //确保服务依赖的正确性,放到所有注册服务代码后调用 //if (_env.IsDevelopment()) //{ services.AddAutoReview( new DependencyInjectionAssert() { IgnoreTypes = new[] { "Microsoft.AspNetCore.Mvc.Razor.Internal.TagHelperComponentManager", "Microsoft.Extensions.DependencyInjection.IServiceScopeFactory" } } ); //} }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); ServiceConfigure.Configure(services, Directory.GetCurrentDirectory(), ConfigurationConstans.DefaultJsonSettingFileName); }