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 application.

Like MiniProfiler, Rin is a middleware that captures the traffic between the application and the user.

It shows you a friendly UI about the requests in the browser. You can see how much time the request took and each method in particular. Using this library, you can debug your application more efficiently.

Configure Rin on your ASP.NET website

  1. Install the Nuget Packages
    Install-Package Rin
    Install-Package Rin.Mvc
  2. Configure the Rin Logger
    var builder = WebApplication.CreateBuilder(args);
    builder.Logging.AddRinLogger();
  3. Add the services:
    builder.Services.AddRazorPages()
        .AddRinMvcSupport();
    builder.Services.AddRin();
  4. Include in the request pipeline the Rin Middlewares:
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }
    else
    {
        app.UseRin();
        app.UseRinMvcSupport();
        app.UseRinDiagnosticsHandler();
    }
  5. The final Program class should look like this:
    using Rin;
    using Rin.Extensions;
    
    var builder = WebApplication.CreateBuilder(args);
    builder.Logging.AddRinLogger();
    // Add services to the container.
    builder.Services.AddRazorPages()
        .AddRinMvcSupport();
    builder.Services.AddRin();
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, 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 in the layout file:
    @await RenderSectionAsync("Scripts", required: false)
    <environment include="Development">
      @RinHelper.RenderInViewInspector()
    </environment>
    </body>
    </html>

Test the Rin Library

Once you configure the Rib library, you should run the application.

In the left corner, you will see a small widget indicating how much time the request took. If you hover over it, a small window appears. It shows you the trace of the request.Rin Trace Requests

The Rin Inspector keeps a history of all the requests. You can see each request’s headers, body, and trace. This middleware captures the exceptions and logs from libraries like NLog or ILogger.

Rin Inspector

 

Leave a Comment