Add authentication
This commit is contained in:
parent
8f0c4c0a45
commit
a2d84e182d
11 changed files with 206 additions and 21 deletions
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -27,15 +28,18 @@ namespace Website
|
|||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||
});
|
||||
|
||||
services.AddSingleton<IConfiguration>(Configuration);
|
||||
services.AddSingleton(Configuration);
|
||||
RegisterRepositories(services);
|
||||
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
||||
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
}
|
||||
|
||||
private void RegisterRepositories(IServiceCollection services) =>
|
||||
services.AddSingleton<IDatabaseProvider, MySQLDatabaseProvider>()
|
||||
.AddSingleton<BlogRepository, BlogRepository>();
|
||||
.AddSingleton<BlogRepository, BlogRepository>()
|
||||
.AddSingleton<UserRepository, UserRepository>();
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
|
@ -51,24 +55,23 @@ namespace Website
|
|||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseStatusCodePagesWithReExecute("/Error/PageNotFound");
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "blogPages",
|
||||
template: "blog/{action}/{page:int}",
|
||||
defaults: new { controller = "Blog", action = "Page", page = 1 });
|
||||
routes.MapRoute(
|
||||
name: "blogView",
|
||||
template: "blog/view/{url}",
|
||||
defaults: new { controller = "Blog", action = "Entry"});
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
app.UseStatusCodePagesWithReExecute("/Error/PageNotFound")
|
||||
.UseHttpsRedirection()
|
||||
.UseStaticFiles()
|
||||
.UseAuthentication()
|
||||
.UseMvc(routes => {
|
||||
routes.MapRoute(
|
||||
name: "blogPages",
|
||||
template: "blog/{action}/{page:int}",
|
||||
defaults: new {controller = "Blog", action = "Page", page = 1});
|
||||
routes.MapRoute(
|
||||
name: "blogView",
|
||||
template: "blog/view/{url}",
|
||||
defaults: new {controller = "Blog", action = "Entry"});
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue