コード例 #1
0
ファイル: Startup.cs プロジェクト: ciaran92/BloggerApp
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddDbContext<TestDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(
                options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                );

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            //services.AddDbContext<TestDBContext>(options => options.UseSqlServer(connection));
            services.AddDbContext <TestDBContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));

            DependencyInjectionConfig.AddScope(services);
            services.AddAuthentication(GetAuthenticationOptions).AddJwtBearer(GetJwtBearerOptions);
            //JwtConfig.AddJwtAuthentication(services, Configuration);

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll", p =>
                {
                    p.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
        }
コード例 #2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     DependencyInjectionConfig.AddScope(services);
     DBContextConfig.Initialize(services);
     services.AddCors();
     services.AddMvc();
 }
コード例 #3
0
        // 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)
        {
            DependencyInjectionConfig.AddScope(services);
            services.AddControllers();

            services.AddCors(c =>
            {
                c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
            });
        }
コード例 #4
0
        // 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, IConfiguration configuration)
        {
            _configuration = configuration;
            DependencyInjectionConfig.AddScope(services);

            JwtTokenConfig.AddAuthentication(services, configuration);

            DBContextConfig.Initialize(services, configuration);

            services.AddMvc();
        }
コード例 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.AddScope(services);

            //se agrega el context con un string base en appsettings

            StringFactory.SetStringEmpresas(Configuration.GetConnectionString("EmpresasString"));

            services.AddDbContext <EmpresasContext>(options =>
                                                    options.UseSqlServer(StringFactory.StringEmpresas));

            StringFactory.SetStringGE(Configuration.GetConnectionString("GrupoEmpresarialString"));

            services.AddDbContext <GrupoEmpresarialContext>(options =>
                                                            options.UseSqlServer(StringFactory.StringGE));

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath        = "/Cuenta/Login/";
                options.AccessDeniedPath = "/Cuenta/Login/";
            });

            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");

            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                //options.IdleTimeout = TimeSpan.FromMinutes(30);
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                options.Cookie.IsEssential = true;
            });

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.Configure <IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });
        }
コード例 #6
0
ファイル: Startup.cs プロジェクト: NielsTyler/SortingService
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     DependencyInjectionConfig.AddScope(services);
     services.AddControllers(options =>
                             options.Filters.Add(new HttpResponseExceptionFilter()));
     services.AddControllers();
     services.AddApiVersioning(options => {
         options.AssumeDefaultVersionWhenUnspecified = true;
         options.DefaultApiVersion = ApiVersion.Default;
         options.ApiVersionReader  = new HeaderApiVersionReader("X-Version");//MediaTypeApiVersionReader("X-version");
         options.ReportApiVersions = true;
     });
 }
コード例 #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            // Add framework services.
            services.AddControllers();
            //.AddNewtonsoftJson(options =>
            //{
            //    options.SerializerSettings. = new DefaultContractResolver();
            //});

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddSingleton <IConfiguration>(Configuration);

            // Add DbContext
            services.AddDbContext <MavcPigeonDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            DependencyInjectionConfig.AddScope(services);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });

            services.AddMvc();

            //Add Compression
            services.AddResponseCompression();
            services.Configure <GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });

            services.AddControllersWithViews();
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }
コード例 #8
0
        // 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)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            #region DbContext
            services.AddDbContext <ApplicationDbContext>();
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();
            #endregion

            #region JWT
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // => remove default claims
            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = Config["JwtIssuer"],
                    ValidAudience    = Config["JwtIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Config["JwtKey"])),
                    ClockSkew        = TimeSpan.Zero // remove delay of token when expire
                };
            });
            #endregion

            #region AutoMapper
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapping());
            });
            IMapper mapper = mappingConfig.CreateMapper();
            services.AddSingleton(mapper);
            #endregion

            #region DependencyInjectionConfig
            DependencyInjectionConfig.AddScope(services);
            #endregion

            services.AddMvc();
        }
コード例 #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.AddScope(services);
            JwtTokenConfig.AddAuthentication(services, Configuration);
            DBContextConfig.Initialize(services, Configuration);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //var connection = @"Server=(localdb)\mssqllocaldb;Organigrama.AspNetCore.NewDb;Trusted_Connection=True;ConnectRetryCount=0";
            //services.AddDbContext<ApplicationContext>
            //(options => options.UseSqlServer(connection));
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration => {
                configuration.RootPath = "ClientApp/dist";
            });
        }
コード例 #10
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     DependencyInjectionConfig.AddScope(services);
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.Configure <ConfigurationManager>(Configuration.GetSection("ConfigurationManager"));
     JwtTokenConfig.AddAuthentication(services, Configuration);
     services.AddMvc()
     .AddJsonOptions(options =>
     {
         options.SerializerSettings.ContractResolver = new DefaultContractResolver();
         // This prevents the json serializer from parsing dates
         options.SerializerSettings.DateParseHandling = DateParseHandling.None;
         // This changes how the timezone is converted - RoundtripKind keeps the timezone that was provided and doesn't convert it
         options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     });
 }
コード例 #11
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <DataContext>(m => m.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
     services.AddControllers();
     services.AddAutoMapper(typeof(Startup));
     //injecting dependency at run time
     DependencyInjectionConfig.AddScope(services);
     services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
     .AddJwtBearer(Options =>
     {
         Options.TokenValidationParameters = new TokenValidationParameters
         {
             ValidateIssuerSigningKey = true,
             IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII
                                                                 .GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
             ValidateIssuer   = false,
             ValidateAudience = false
         };
         services.AddCors();
     });
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
 }
コード例 #12
0
ファイル: Startup.cs プロジェクト: altivaIsacc/altivawebapp
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.AddScope(services);

            string ruta = Path.Combine(entorno.WebRootPath, "altivalog");

            AltivaLog.Log llog = new AltivaLog.Log(ruta);
            services.AddDbContext <EmpresasContext>();
            services.AddDbContext <GrupoEmpresarialContext>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath        = "/Cuenta/Login/";
                options.AccessDeniedPath = "/Cuenta/Login/";
            });

            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");


            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                options.IdleTimeout     = TimeSpan.FromDays(360);
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                options.Cookie.IsEssential = true;
            });

            //var supportedCultures = new[] { "es-CR", "en-US" };

            var defaultDateCulture = "es-CR";
            var cr = new CultureInfo(defaultDateCulture);

            cr.NumberFormat.NumberDecimalSeparator   = ",";
            cr.NumberFormat.CurrencyDecimalSeparator = ",";

            var us = new CultureInfo("en-US");

            us.NumberFormat.NumberDecimalSeparator   = ",";
            us.NumberFormat.CurrencyDecimalSeparator = ",";


            var localizationOptions = new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture(cr),
                SupportedCultures     = new List <CultureInfo>
                {
                    cr,
                    us
                },
                SupportedUICultures = new List <CultureInfo>
                {
                    cr,
                    us
                }
            };

            localizationOptions
            .RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider()
            {
                Options = localizationOptions
            });

            //localizationOptions.AddSupportedCultures(supportedCultures)
            //    .AddSupportedUICultures(supportedCultures)
            //    .SetDefaultCulture(supportedCultures[0])
            //    .RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider() { Options = localizationOptions });


            services.AddSingleton(localizationOptions);
            services.AddLocalization(opt => opt.ResourcesPath = "Resources");

            services.AddMvc(mvcOptions =>
            {
                mvcOptions.Filters.Add(typeof(CultureRedirectFilter));
                mvcOptions.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline)));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
            .AddDataAnnotationsLocalization();

            services.Configure <IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });

            services.AddHttpContextAccessor();
            services.AddDistributedMemoryCache();
        }
コード例 #13
0
ファイル: Startup.cs プロジェクト: rukfash/Blogging
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <BloggingContext>(options => options.UseSqlServer(Configuration.GetConnectionString("BloggingContext")));
     DependencyInjectionConfig.AddScope(services);
     services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
 }