using BuddyFinance.Admin.Filters; using BuddyFinance.Admin.Models; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Rewrite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using System; namespace BuddyFinance.Admin { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(); services.AddSession(m => m.IdleTimeout = TimeSpan.FromMinutes(120)); services.AddRouting(options => options.LowercaseUrls = true); services.AddControllersWithViews(options => { options.Filters.Add(typeof(LogExceptionAttribute)); // options.Filters.Add(new AuthenticateAttribute()); }).AddRazorRuntimeCompilation(); // .AddMvc(options => //{ // options.Filters.Add(typeof(LogExceptionAttribute)); // // options.Filters.Add(new AuthenticateAttribute()); //}); //.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("buddyfinance"))); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.ReturnUrlParameter = "returnUrl"; options.LoginPath = new PathString("/account/login"); }); services.AddAuthorization(options => { options.AddPolicy("LoggedIn", policy => policy.AddRequirements(new AuthorizeRequirement())); }); services.AddTransient(); //services.AddSingleton(provider => new BuddyFinance.Integration(WcfService.EndpointConfiguration.WSHttpBinding, GetEndPoint())); } //private EndpointAddress GetEndPoint() //{ // EndpointAddress endpointAddress; // string endPointUrl = Configuration.GetSection("transunionService").GetValue("EndpointUrl"); // if (!string.IsNullOrEmpty(endPointUrl)) // { // endpointAddress = new System.ServiceModel.EndpointAddress(endPointUrl); // } // else // { // throw new Exception("Error in wcfService configuration file."); // } // return endpointAddress; //} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); //app.UseDatabaseErrorPage(); //app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseSession(); //var rewriteOptions = new RewriteOptions() // //.AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 44370); //localhost // .AddRedirectToHttps(StatusCodes.Status301MovedPermanently); //qa or prod //app.UseRewriter(rewriteOptions); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "admin", pattern: "{area:exists}/{controller=Home}/{action=Index}" ).RequireAuthorization(); endpoints.MapControllerRoute( name: "activate_account", pattern: "profile/activate/{type?}", defaults: new { controller = "Profile", action = "Activate" } ).RequireAuthorization(); endpoints.MapControllerRoute( name: "profile", pattern: "profile/{*section}", defaults: new { controller = "Profile", action = "Index" } ).RequireAuthorization(); endpoints.MapControllerRoute( name: "lender", pattern: "lender/{*section}", defaults: new { controller = "Lender", action = "Dashboard" } ).RequireAuthorization(); endpoints.MapControllerRoute( name: "borrower", pattern: "borrower/{*section}", defaults: new { controller = "Borrower", action = "Dashboard" } ).RequireAuthorization(); endpoints.MapDefaultControllerRoute().RequireAuthorization(); }); //app.UseMvc(routes => //{ // routes.MapRoute( // name: "admin", // template: "{area:exists}/{controller=Home}/{action=Index}" // ); // routes.MapRoute( // name: "activate_account", // template: "profile/activate/{type?}", // defaults: new { controller = "Profile", action = "Activate" } // ); // routes.MapRoute( // name: "profile", // template: "profile/{*section}", // defaults: new { controller = "Profile", action = "Index" } // ); // routes.MapRoute( // name: "lender", // template: "lender/{*section}", // defaults: new { controller = "Lender", action = "Dashboard" } // ); // routes.MapRoute( // name: "borrower", // template: "borrower/{*section}", // defaults: new { controller = "Borrower", action = "Dashboard" } // ); // routes.MapRoute( // name: "default", // template: "{controller=Home}/{action=Index}/{id?}"); //}); } } }