question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to manually render UI without MVC dependency?

See original GitHub issue

I am using MiniProfiler in an ASP.NET WebAPI service host (that will soon transition to ASP.NET Core). The application using it is is developed separately using JS. I am currently using RenderPlainText to provide information back from an end-point, but it does not render everything i would like (SQL not expanded as far as i can see ). I could of course just write some custom code to print what i like, but it seems silly when there is an actual UI available.

I noticed that there are methods like RenderIncludes so i was wondering if there would happen to be a nice way to generate the necessary HTML statically or similar?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
rhullahcommented, Apr 19, 2020

I’d like to šŸ‘ this too.

We have a SPA frontend calling an ASP.NET API backend which uses MiniProfiler. And I’d like to expose the profiler results in the UI. I’d love for there to be a ā€œMiniProfiler.(JS Framework)ā€ package I could install into my frontend to surface those results. Or at least some sort of direction/documentation of how to add the appropriate JS includes/scripts, to then expose the UI/data appropriately.

1reaction
RubberChickenParadisecommented, Mar 16, 2020

I just ran into this. I found this stack overflow post https://stackoverflow.com/questions/53321634/unable-to-print-query-using-miniprofiler and use this code

public static string CustomRenderPlainText(this MiniProfiler profiler, bool htmlEncode = false)
        {
            if (profiler == null) return string.Empty;

            var text = StringBuilderCache.Get()
                .Append(htmlEncode ? WebUtility.HtmlEncode(Environment.MachineName) : Environment.MachineName)
                .Append(" at ")
                .Append(DateTime.UtcNow)
                .AppendLine();

            var timings = new Stack<Timing>();
            timings.Push(profiler.Root);

            while (timings.Count > 0)
            {
                var timing = timings.Pop();

                text.AppendFormat("{0} {1} = {2:###,##0.##}[ms]",
                    new string('>', timing.Depth),
                    htmlEncode ? WebUtility.HtmlEncode(timing.Name) : timing.Name,
                    timing.DurationMilliseconds);

                if (timing.HasCustomTimings)
                {
                    // TODO: Customize this code block.

                    // Custom timings grouped by category. Collect all custom timings in a list.
                    var customTimingsFlat = new List<KeyValuePair<string, CustomTiming>>(capacity: timing.CustomTimings.Sum(ct => ct.Value.Count));
                    foreach (var pair in timing.CustomTimings)
                    {
                        var type = pair.Key;
                        var customTimings = pair.Value;

                        customTimingsFlat.AddRange(pair.Value.Select(ct => KeyValuePair.Create(type, ct)));
                        text.AppendFormat(" ({0} = {1:###,##0.##}[ms] in {2} cmd{3})",
                            type,
                            customTimings.Sum(ct => ct.DurationMilliseconds),
                            customTimings.Count,
                            customTimings.Count == 1 ? string.Empty : "s");
                    }

                    foreach (var pair in customTimingsFlat.OrderBy(kvp => kvp.Value.StartMilliseconds))
                    {
                        var type = pair.Key;
                        var ct = pair.Value;

                        text.AppendLine();
                        var mainPart = string.Format("{0}{1} {2:###,##0.##}[ms] +{3:###,##0.##}[ms] ",
                                            new string(' ', timing.Depth + 2),
                                            type,
                                            ct.DurationMilliseconds,
                                            ct.StartMilliseconds);
                        text.Append(mainPart);
                        // Shift command text to closer to the command for better readability.
                        var prefix = new string(' ', mainPart.Length);
                        string cmdLine = null;
                        using (var reader = new StringReader(ct.CommandString))
                        {
                            while ((cmdLine = reader.ReadLine()) != null)
                            {
                                text.Append(cmdLine);
                                if (reader.Peek() == -1 && profiler.Options.ExcludeStackTraceSnippetFromCustomTimings)
                                {
                                    break;
                                }
                                text.AppendLine();
                                text.Append(prefix);
                            }
                        }

                        if (profiler.Options.ExcludeStackTraceSnippetFromCustomTimings)
                        {
                            continue;
                        }
                        text.Append(ct.StackTraceSnippet);
                    }
                }

                text.AppendLine();

                if (timing.HasChildren)
                {
                    var children = timing.Children;
                    for (var i = children.Count - 1; i >= 0; i--) timings.Push(children[i]);
                }
            }

            return text.ToStringRecycle();
        }

It got me what I needed and can obviously be improved upon for your needs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundling and minification without ASP.NET MVC
It is absolutely possible to use the bundling and minification in a blank project. Use Nuget to install the package: Install-PackageĀ ...
Read more >
ASP.NET Core Razor component rendering
Learn about Razor component rendering in ASP.NET Core Blazor apps, including when to manually trigger a component to render.
Read more >
Don't replace your View Components with Razor ...
In this post I take a brief look at Razor Components, and whether you should consider using their static render mode instead of...
Read more >
Back to Basics: Rendering Razor Views to String in ASP.NET ...
The rendering method takes a view path, model and a controller context to retrieve the view using the active RazorViewEngine of the application....
Read more >
Getting Started | Serving Web Content with Spring MVC
Learn how to create a web page with Spring MVC and Thymeleaf. ... Click Dependencies and select Spring Web, Thymeleaf, and Spring Boot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found