Thursday, April 25, 2024
HomeC#Rin - Request/Response Inspector Middleware for ASP.NET Core

Rin – Request/Response Inspector Middleware for ASP.NET Core


Rin is a .NET library for ASP.NET Core, which inspects the requests and responses of the appliance.

Like MiniProfiler, Rin is a middleware that captures the visitors between the appliance and the person.

It reveals you a pleasant UI concerning the requests within the browser. You’ll be able to see how a lot time the request took and every technique particularly. Utilizing this library, you possibly can debug your software extra effectively.

Configure Rin in your ASP.NET web site

  1. Set up the Nuget Packages
    Set up-Bundle Rin
    Set up-Bundle Rin.Mvc
  2. Configure the Rin Logger
    var builder = WebApplication.CreateBuilder(args);
    builder.Logging.AddRinLogger();
  3. Add the providers:
    builder.Providers.AddRazorPages()
        .AddRinMvcSupport();
    builder.Providers.AddRin();
  4. Embody within the request pipeline the Rin Middlewares:
    if (!app.Setting.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }
    else
    {
        app.UseRin();
        app.UseRinMvcSupport();
        app.UseRinDiagnosticsHandler();
    }
  5. The ultimate Program class ought to seem like this:
    utilizing Rin;
    utilizing Rin.Extensions;
    
    var builder = WebApplication.CreateBuilder(args);
    builder.Logging.AddRinLogger();
    // Add providers to the container.
    builder.Providers.AddRazorPages()
        .AddRinMvcSupport();
    builder.Providers.AddRin();
    
    var app = builder.Construct();
    
    // Configure the HTTP request pipeline.
    if (!app.Setting.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS worth is 30 days. It's possible you'll need to change this for manufacturing eventualities, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }
    else
    {
        app.UseRin();
        app.UseRinMvcSupport();
        app.UseRinDiagnosticsHandler();
    }
    
    app.UseHttpsRedirection();
    app.UseStaticFiles();
    
    app.UseRouting();
    
    app.UseAuthorization();
    
    app.MapRazorPages();
    
    app.Run();
    
  6. Inject the RinHelper in  _ViewImports.cshtml file:
    @inject Rin.Mvc.View.RinHelperService RinHelper
  7. Render the view within the format file:
    @await RenderSectionAsync("Scripts", required: false)
    <atmosphere embody="Improvement">
      @RinHelper.RenderInViewInspector()
    </atmosphere>
    </physique>
    </html>

Take a look at the Rin Library

When you configure the Rib library, it is best to run the appliance.

Within the left nook, you will note a small widget indicating how a lot time the request took. Should you hover over it, a small window seems. It reveals you the hint of the request.Rin Trace Requests

The Rin Inspector retains a historical past of all of the requests. You’ll be able to see every request’s headers, physique, and hint. This middleware captures the exceptions and logs from libraries like NLog or ILogger.

Rin Inspector

 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments