Guest User

Untitled

a guest
May 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Authentication.Cookies;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Builder;
  8. using Microsoft.AspNetCore.Hosting;
  9. using Microsoft.AspNetCore.Mvc.Authorization;
  10. using Microsoft.AspNetCore.Routing;
  11. using Microsoft.Extensions.DependencyInjection;
  12.  
  13. namespace WebApp {
  14. public class Startup {
  15. public void ConfigureServices(IServiceCollection services) {
  16. // クッキー認証を行うためにサービスを登録
  17. services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
  18. .AddCookie();
  19.  
  20. services.AddMvc(options => {
  21. var policy = new AuthorizationPolicyBuilder()
  22. .RequireAuthenticatedUser()
  23. .Build();
  24. options.Filters.Add(new AuthorizeFilter(policy));
  25. });
  26.  
  27. services.Configure<RouteOptions>(options => {
  28. options.LowercaseUrls = true;
  29. });
  30. }
  31.  
  32. public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
  33. if (env.IsDevelopment()) {
  34. app.UseDeveloperExceptionPage();
  35. }
  36.  
  37. app.UseMvc(routes => {
  38. routes.MapRoute(
  39. name: "default",
  40. template: "{controller=Default}/{action=Index}/{id?}");
  41. });
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment