1 // Copyright (c) .NET Foundation. All rights reserved.
2 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3 
4 using Microsoft.AspNetCore.Builder;
5 using Microsoft.AspNetCore.Hosting;
6 using Microsoft.AspNetCore.Identity;
7 using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
8 using Microsoft.EntityFrameworkCore;
9 using Microsoft.Extensions.Configuration;
10 using Microsoft.Extensions.DependencyInjection;
11 
12 namespace Identity.DefaultUI.WebSite
13 {
14     public class NoIdentityStartup
15     {
NoIdentityStartup(IConfiguration configuration)16         public NoIdentityStartup(IConfiguration configuration)
17         {
18             Configuration = configuration;
19         }
20 
21         public IConfiguration Configuration { get; }
22 
23         // This method gets called by the runtime. Use this method to add services to the container.
ConfigureServices(IServiceCollection services)24         public void ConfigureServices(IServiceCollection services)
25         {
26             services.Configure<CookiePolicyOptions>(options =>
27             {
28                 // This lambda determines whether user consent for non-essential cookies is needed for a given request.
29                 options.CheckConsentNeeded = context => true;
30             });
31 
32             services.AddMvc()
33                 .AddRazorPagesOptions(options =>
34                 {
35                     options.Conventions.AuthorizeFolder("/Areas/Identity/Pages/Account/Manage");
36                     options.Conventions.AuthorizePage("/Areas/Identity/Pages/Account/Logout");
37                 });
38         }
39 
40         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Configure(IApplicationBuilder app, IHostingEnvironment env)41         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
42         {
43             if (env.IsDevelopment())
44             {
45                 app.UseDeveloperExceptionPage();
46                 app.UseDatabaseErrorPage();
47             }
48             else
49             {
50                 app.UseExceptionHandler("/Error");
51                 app.UseHsts();
52             }
53 
54             app.UseHttpsRedirection();
55             app.UseStaticFiles();
56             app.UseCookiePolicy();
57 
58             app.UseAuthentication();
59 
60             app.UseMvc();
61         }
62     }
63 }
64