public void Configure(IApplicationBuilder builder, IConfiguration configuration) { builder.UseMultipleErrorHandlerPipelines(app => { MapExtensions.Map( app, "/throws", inner => RunExtensions.Run( inner, async ctx => { await Task.Yield(); throw new Exception("Map exception"); })); MvcApplicationBuilderExtensions.UseMvc( app, routes => { MapRouteRouteBuilderExtensions.MapRoute(routes, "custom", "Test/{action=Index}", new { Controller = "MyTest" }); MapRouteRouteBuilderExtensions.MapRoute(routes, "default", "{controller=Home}/{action=Index}/{id?}"); }); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStatusCodePagesWithReExecute("/Status/Status/{0}"); app.UseStaticFiles(); app.UseIdentity(); var googleClientId = Configuration["Authentication:Google:ClientId"]; var googleClientSecret = Configuration["Authentication:Google:ClientSecret"]; if (!string.IsNullOrEmpty(googleClientId) && !string.IsNullOrEmpty(googleClientSecret)) { var options = new GoogleOptions(); options.ClientId = googleClientId; options.ClientSecret = googleClientSecret; options.Scope.Add("email"); options.Scope.Add("profile"); } var facebookAppId = Configuration["Authentication:Facebook:AppId"]; var facebookAppSecret = Configuration["Authentication:Facebook:AppSecret"]; if (!string.IsNullOrEmpty(facebookAppId) && !string.IsNullOrEmpty(facebookAppSecret)) { app.UseFacebookAuthentication(new FacebookOptions { AppId = facebookAppId, AppSecret = facebookAppSecret }); } app.UseJsEngine(); app.UseMvc(routes => { MapRouteRouteBuilderExtensions.MapRoute(routes, name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.Use((context, next) => { context.Response.StatusCode = 404; return(next()); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStatusCodePagesWithReExecute("/Status/Status/{0}"); app.UseStaticFiles(); app.UseIdentity(); var googleClientId = Configuration["Authentication:Google:ClientId"]; var googleClientSecret = Configuration["Authentication:Google:ClientSecret"]; if (!string.IsNullOrEmpty(googleClientId) && !string.IsNullOrEmpty(googleClientSecret)) { var options = new GoogleOptions(); options.ClientId = googleClientId; options.ClientSecret = googleClientSecret; options.Scope.Add("email"); options.Scope.Add("profile"); } var facebookAppId = Configuration["Authentication:Facebook:AppId"]; var facebookAppSecret = Configuration["Authentication:Facebook:AppSecret"]; if (!string.IsNullOrEmpty(facebookAppId) && !string.IsNullOrEmpty(facebookAppSecret)) { app.UseFacebookAuthentication(new FacebookOptions { AppId = facebookAppId, AppSecret = facebookAppSecret }); } // To authenticate with an instance of IdentityServer4, use the following client. // ---------------------------------- // new Client // { // ClientId = "client", // ClientSecrets = new List<Secret> // { // new Secret("secret".Sha256()) // }, // Flow = Flows.AuthorizationCode, // RedirectUris = new List<string> { "http://localhost:5000/signin-idsvr" }, // AllowedScopes = new List<string> // { // StandardScopes.OpenId.Name, // StandardScopes.Profile.Name, // StandardScopes.Email.Name // } // } // ---------------------------------- // Make sure IdentityServer is listening locally on port 5001. // Then, uncomment the following. //app.UseOAuthAuthentication(options => //{ // options.DisplayName = "Identity Server"; // options.CallbackPath = new PathString("/signin-idsvr"); // options.AuthenticationScheme = "idsvr"; // options.ClientSecret = "secret"; // options.ClientId = "client"; // options.AuthorizationEndpoint = "http://localhost:5001/connect/authorize"; // options.TokenEndpoint = "http://localhost:5001/connect/token"; // options.UserInformationEndpoint = "http://localhost:5001/connect/userinfo"; // options.Scope.Add("openid"); // options.Scope.Add("profile"); // options.Scope.Add("email"); // options.Events = new OAuthEvents // { // OnCreatingTicket = async context => // { // var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); // request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); // request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted); // response.EnsureSuccessStatusCode(); // var user = JObject.Parse(await response.Content.ReadAsStringAsync()); // var id = user.Value<string>("sub"); // if (!string.IsNullOrEmpty(id)) // { // context.Identity.AddClaim(new Claim( // ClaimTypes.NameIdentifier, id, // ClaimValueTypes.String, context.Options.ClaimsIssuer)); // } // var name = user.Value<string>("name"); // if (!string.IsNullOrEmpty(name)) // { // context.Identity.AddClaim(new Claim( // ClaimTypes.Name, name, // ClaimValueTypes.String, context.Options.ClaimsIssuer)); // } // var email = user.Value<string>("email"); // if (!string.IsNullOrEmpty(email)) // { // context.Identity.AddClaim(new Claim( // ClaimTypes.Email, email, // ClaimValueTypes.String, context.Options.ClaimsIssuer)); // } // } // }; //}); app.UseJsEngine(); // gives a js engine to each request, required when using the JsViewEngine app.UseMvc(routes => { MapRouteRouteBuilderExtensions.MapRoute(routes, name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); app.Use((context, next) => { context.Response.StatusCode = 404; return(next()); }); }