using Angular2Template.Models; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.IO; namespace Angular2AppTemplate { public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); //Add Entity Framework services services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultDatabase"))); // Register the Identity services. services.AddIdentity(o => { o.Password.RequireDigit = false; o.Password.RequireLowercase = false; o.Password.RequireUppercase = false; o.Password.RequireNonAlphanumeric = false; ; o.Password.RequiredLength = 3; }) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); // Register the OpenIddict services, including the default Entity Framework stores. services.AddOpenIddict() // Enable the token endpoint (required to use the password flow). .EnableTokenEndpoint("/api/Account/Login") // Allow client applications to use the grant_type=password flow. .AllowPasswordFlow() // During development, you can disable the HTTPS requirement. .DisableHttpsRequirement() // Register a new ephemeral key, that is discarded when the application // shuts down. Tokens signed using this key are automatically invalidated. // This method should only be used during development. .AddEphemeralSigningKey(); // Inject an implementation of ISwaggerProvider with defaulted settings applied services.AddSwaggerGen(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { //If ASP.net router doesn't recognize path, then we are assuming that Angular2 router will know something app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.Contains("/api/")) { context.Request.Path = "/index.html"; // Put your Angular root page here await next(); } }); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseIdentity(); app.UseOAuthValidation(); app.UseOpenIddict(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUi(); } } }