Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// <summary>
        /// The Configure
        /// </summary>
        /// <param name="app">The app<see cref="IApplicationBuilder"/></param>
        /// <param name="env">The env<see cref="Microsoft.Extensions.Hosting.IHostEnvironment"/></param>
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                //app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();


            ///

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthorization();
            app.UseAuthentication();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapFallbackToController("Index", "Home");
            });
        }
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }


            app.UseStaticFiles();
            app.UseRouting();
            app.UseCors();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();


            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "GoVagas");
                c.RoutePrefix = string.Empty;
            });

            app.UseAuthentication();
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, Microsoft.Extensions.Hosting.IHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            //app.UseMvc();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });
        }
    private static X509Certificate2 LoadCertificate(EndpointConfiguration config, Microsoft.Extensions.Hosting.IHostEnvironment environment)
    {
        if (config.StoreName != null && config.StoreLocation != null)
        {
            using (var store = new X509Store(config.StoreName, Enum.Parse <StoreLocation>(config.StoreLocation)))
            {
                store.Open(OpenFlags.ReadOnly);
                var certificate = store.Certificates.Find(
                    X509FindType.FindBySubjectName,
                    config.Host,
                    validOnly: !environment.IsDevelopment());

                if (certificate.Count == 0)
                {
                    throw new InvalidOperationException($"Certificate not found for {config.Host}.");
                }

                return(certificate[0]);
            }
        }

        if (config.FilePath != null && config.Password != null)
        {
            return(new X509Certificate2(config.FilePath, config.Password));
        }

        throw new InvalidOperationException("No valid certificate configuration found for the current endpoint.");
    }
Пример #5
0
        public Startup(Microsoft.Extensions.Hosting.IHostEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings{env.EnvironmentName}.json", optional: true)
                          .AddJsonFile("simpliPromo.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"simpliPromo{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            Configuration = builder.Build();
        }
Пример #6
0
        private static void InitializeElasticSearch(IServiceCollection services, IConfiguration configuration, IHostingEnvironment environment = null)
        {
            var connectionString       = $"{configuration["ElasticSearch:Connection"]}";
            var numberOfReplicasConfig = $"{configuration["ElasticSearch:NumberOfReplicas"]}";
            var numberOfShardsConfig   = $"{configuration["ElasticSearch:NumberOfShards"]}";

            if (string.IsNullOrWhiteSpace(numberOfReplicasConfig) || int.TryParse(numberOfReplicasConfig, out var numberOfReplicas) == false)
            {
                numberOfReplicas = 5;
            }

            if (string.IsNullOrWhiteSpace(numberOfShardsConfig) || int.TryParse(numberOfShardsConfig, out var numberOfShards))
            {
                numberOfShards = 5;
            }

            var enableDebugMode = environment != null && environment.IsDevelopment();

            services.AddSingleton(new ElasticSearchSettings(numberOfReplicas, numberOfShards));
            services.AddSingleton <IElasticClient>(ElasticSearchSetup.Initialize(connectionString, true));
            services.AddSingleton <IElasticSearchService, ElasticSearchService>();
            services.AddTransient <ISearchFiltersService <ProductIndexItem>, SearchFiltersFiltersService <ProductIndexItem> >();
        }
Пример #7
0
        public async Task InvokeAsync(HttpContext context)
        {
            try
            {
                await _next(context);
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                context.Response.ContentType = "application/json";
                context.Response.StatusCode  = (int)System.Net.HttpStatusCode.InternalServerError;
                var response = _env.IsDevelopment()
                ? new ApiException((int)HttpStatusCode.InternalServerError, ex.Message, ex.StackTrace.ToString())
                : new ApiException((int)HttpStatusCode.InternalServerError);

                var options = new System.Text.Json.JsonSerializerOptions {
                    PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase
                };
                var json = System.Text.Json.JsonSerializer.Serialize(response, options);

                await context.Response.WriteAsync(json);
            }
        }