Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Angular_Core_DBContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                //app.UseHsts();
                app.UseExceptionHandler(builder =>
                {
                    builder.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                                                   var error = context.Features.Get <IExceptionHandlerFeature>();
                                                   if (error != null)
                                                   {
                                                       context.Response.AddApplicationError(error.Error.Message);
                                                       await context.Response.WriteAsync(error.Error.Message);
                                                   }
                                });
                });
            }

            db.Database.EnsureCreated();

            //app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseAuthentication();
            app.UseAuthorization();
            //app.UseMvc();

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

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Exemplo n.º 2
0
        public static void SeedUsers(Angular_Core_DBContext context)
        {
            if (!context.Users.Any())
            {
                var userData = System.IO.File.ReadAllText("Data/UserSeedData.json");
                var users    = JsonConvert.DeserializeObject <List <User> >(userData);
                foreach (var user in users)
                {
                    byte[] passwordHash, passwordSalt;
                    CreatePasswordHash("password", out passwordHash, out passwordSalt);

                    user.PasswordHash = passwordHash;
                    user.PasswordSalt = passwordSalt;
                    user.Username     = user.Username.ToLower();
                    context.Users.Add(user);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public AuthRepository(Angular_Core_DBContext context)
 {
     _context = context;
 }
Exemplo n.º 4
0
 public ValuesController(Angular_Core_DBContext context)
 {
     this._context = context;
 }
Exemplo n.º 5
0
 public DatingRepository(Angular_Core_DBContext context)
 {
     _context = context;
 }