|
| 1 | +using Microsoft.AspNetCore.Authentication.AzureAD.UI; |
| 2 | +using Microsoft.AspNetCore.Authorization; |
| 3 | +using Microsoft.AspNetCore.Builder; |
| 4 | +using Microsoft.AspNetCore.Hosting; |
| 5 | +using Microsoft.AspNetCore.Http; |
| 6 | +using Microsoft.AspNetCore.Mvc; |
| 7 | +using Microsoft.AspNetCore.Mvc.Authorization; |
| 8 | +using Microsoft.Extensions.Configuration; |
| 9 | +using Microsoft.Extensions.DependencyInjection; |
| 10 | +using Microsoft.Identity.Web; |
| 11 | + |
| 12 | +namespace WebApp_OpenIDConnect_DotNet |
| 13 | +{ |
| 14 | + public class Startup |
| 15 | + { |
| 16 | + public Startup(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. |
| 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 | + options.MinimumSameSitePolicy = SameSiteMode.None; |
| 31 | + }); |
| 32 | + |
| 33 | + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); |
| 34 | + } |
| 35 | + |
| 36 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 37 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
| 38 | + { |
| 39 | + if (env.IsDevelopment()) |
| 40 | + { |
| 41 | + app.UseDeveloperExceptionPage(); |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + app.UseExceptionHandler("/Home/Error"); |
| 46 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 47 | + app.UseHsts(); |
| 48 | + } |
| 49 | + |
| 50 | + app.UseHttpsRedirection(); |
| 51 | + app.UseStaticFiles(); |
| 52 | + app.UseCookiePolicy(); |
| 53 | + |
| 54 | + app.UseAuthentication(); |
| 55 | + |
| 56 | + app.UseMvc(routes => |
| 57 | + { |
| 58 | + routes.MapRoute( |
| 59 | + name: "default", |
| 60 | + template: "{controller=Home}/{action=Index}/{id?}"); |
| 61 | + }); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments