Skip to content

Instantly share code, notes, and snippets.

@StephanyBatista
Created April 29, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephanyBatista/24dcfb7aa1412b3c7c236eb61bc30eb5 to your computer and use it in GitHub Desktop.
Save StephanyBatista/24dcfb7aa1412b3c7c236eb61bc30eb5 to your computer and use it in GitHub Desktop.
Example of middleware in Startup class
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseBrowserLink(); //Middleware
app.UseDeveloperExceptionPage(); //Middleware
app.UseDatabaseErrorPage(); //Middleware
}
else
{
app.UseExceptionHandler("/Home/Error"); //Middleware
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
}
}
catch { }
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); //Middleware
app.UseApplicationInsightsExceptionTelemetry(); //Middleware
app.UseStaticFiles(); //Middleware
app.UseIdentity(); //Middleware
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
}); //Middleware
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment