Skip to content

Instantly share code, notes, and snippets.

View CoreProgramm's full-sized avatar
🎯
Focusing

CoreProgramm CoreProgramm

🎯
Focusing
View GitHub Profile
@CoreProgramm
CoreProgramm / Startup.cs
Created April 30, 2020 14:32
Custom Middleware
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCustomLoggerMiddleware();
app.Run(async (context) =>
{
@CoreProgramm
CoreProgramm / Startup.cs
Created April 30, 2020 13:45
Custom Middleware
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCustomLoggerMiddleware();
app.Run(async (context) =>
{
@CoreProgramm
CoreProgramm / CustomLoggerMiddleware.cs
Last active April 30, 2020 12:36
CustomLoggerMiddleware
public class CustomLoggerMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
public CustomLoggerMiddleware(RequestDelegate next, ILoggerFactory logFactory)
{
_next = next;
_logger = logFactory.CreateLogger("MyMiddleware");
_logger.LogInformation("MyMiddleware is Started");
}
@CoreProgramm
CoreProgramm / configure.cs
Created April 29, 2020 18:41
ASP .NET Core Developer Exception Page
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
throw new Exception("Error Occurred while processing your request");
@CoreProgramm
CoreProgramm / configure.cs
Last active April 29, 2020 18:40
ASP .NET Core Developer Exception Page
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
DeveloperExceptionPageOptions developerExceptionPageOptions =
new DeveloperExceptionPageOptions
{
SourceCodeLineCount = 5
};
@CoreProgramm
CoreProgramm / Startup.cs
Created April 29, 2020 16:36
ASP .NET Core Developer Exception Page
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// app.UseFileServer();
app.UseRouting();
@CoreProgramm
CoreProgramm / Startup.cs
Created April 29, 2020 16:16
ASP .NET Core Developer Exception Page
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseFileServer();
app.UseRouting();
@CoreProgramm
CoreProgramm / MyCustomMiddleware.cs
Created April 27, 2020 15:27
Custom Middle Ware
// You may need to install the Microsoft.AspNetCore.Http.Abstractions package into your project
public class MyCustomMiddleware
{
private readonly RequestDelegate _next;
public MyCustomMiddleware(RequestDelegate next)
{
_next = next;
}
@CoreProgramm
CoreProgramm / Program.cs
Created April 27, 2020 13:39
How to Rename wwwroot folder name in ASP.NET Core
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseWebRoot("myCustomRoot")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
@CoreProgramm
CoreProgramm / Startup.cs
Created April 24, 2020 17:01
Static Files in ASP .NET Core
FileServerOptions fileServerOptions = new FileServerOptions();
fileServerOptions.DefaultFilesOptions.DefaultFileNames.Clear();
fileServerOptions.DefaultFilesOptions.DefaultFileNames.Add("custom.html");
app.UseFileServer(fileServerOptions);