Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Authentication.Cookies;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc.Authorization;
- using Microsoft.AspNetCore.Routing;
- using Microsoft.Extensions.DependencyInjection;
- namespace WebApp {
- public class Startup {
- public void ConfigureServices(IServiceCollection services) {
- // クッキー認証を行うためにサービスを登録
- services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
- .AddCookie();
- services.AddMvc(options => {
- var policy = new AuthorizationPolicyBuilder()
- .RequireAuthenticatedUser()
- .Build();
- options.Filters.Add(new AuthorizeFilter(policy));
- });
- services.Configure<RouteOptions>(options => {
- options.LowercaseUrls = true;
- });
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
- if (env.IsDevelopment()) {
- app.UseDeveloperExceptionPage();
- }
- app.UseMvc(routes => {
- routes.MapRoute(
- name: "default",
- template: "{controller=Default}/{action=Index}/{id?}");
- });
- }
- }
- }
Add Comment
Please, Sign In to add comment