Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Localization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Rewrite;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using System.Globalization;
- namespace StartupDemo
- {
- #region Class :: Boost.
- /// <summary>
- /// Class: Boost.cs
- /// Abstract: Serves as the core class of the applications startup directives and features, provides container storage for services, and application pathway for launch.
- /// </summary>
- public class Boost
- {
- #region Properties
- public IConfiguration configObj { get; private set; } = null;
- #endregion
- #region Methods
- public Boost(IHostingEnvironment host)
- {
- var configObject = new ConfigurationBuilder()
- .SetBasePath(host.ContentRootPath)
- .AddJsonFile("config.json")
- .AddEnvironmentVariables();
- configObj = configObject.Build();
- }
- /// <summary>
- /// Service container called by the runtime to provide servics.
- /// </summary>
- /// <param name="services"></param>
- public void ConfigureServices(IServiceCollection services)
- {
- // MVC
- services.AddMvc();
- services.AddCors(opts =>
- {
- opts.AddPolicy("Policy", policyBuilder =>
- {
- policyBuilder.WithOrigins("https://backdoorsecurity.io");
- });
- });
- services.AddMemoryCache();
- services.AddSession();
- services.Configure<MvcOptions>(opt =>
- {
- opt.Filters.Add(new RequireHttpsAttribute());
- });
- }
- /// <summary>
- /// Application pipeline HTTP request pipeline that is called by the runtime to handle incoming HTTP requests...
- /// </summary>
- /// <param name="app"></param>
- public void Configure(IApplicationBuilder app)
- {
- var culturesSupported = new[] { new CultureInfo("en-US") };
- var options = new RewriteOptions()
- .AddRedirectToHttps();
- app.UseRewriter(options);
- app.UseRequestLocalization(new RequestLocalizationOptions
- {
- DefaultRequestCulture = new RequestCulture("en-US"),
- SupportedCultures = culturesSupported,
- SupportedUICultures = culturesSupported
- });
- app.UseDeveloperExceptionPage();
- app.UseDatabaseErrorPage();
- app.UseSession();
- app.UseStaticFiles();
- app.UseMvc(route =>
- {
- route.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}"
- );
- });
- }
- #endregion
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement