使用 Azure 上的 Application Insights 在 ASP.Net MVC 应用程序上捕获搜索查询字符串

Capture search query string on an ASP.Net MVC app using Application Insights on Azure

Azure Application Insights 完全陌生,我想知道如何使用 [=] 在 ASP.Net MVC 应用程序上捕获简单的自由文本 搜索查询 14=].

当用户在应用程序中输入搜索查询时,该应用程序会创建一个 GET 请求。查询看起来像这样 https://example.com/GalleryPartial?search=Application&id=&sort=。我需要捕获的是为 search 输入的文本,在此特定实例中为“应用程序”。

我尝试使用下面 Application Insights life 中的 Logs 来捕获链接:

requests
| where url contains "search"
| summarize count() by bin(timestamp, 1m), URL
| render timechart 

问题:如何在 Application Insights 仪表板中仅提取搜索查询并查看所有搜索查询(用户输入的文本)的列表?除了为应用程序 Azure 捕获一些遥测数据之外,我没有更多的代码。

View如下:

@ModelType IEnumerable(Of Models.UXFilter)
@code
Dim m_Search As String
If ViewContext.Controller.ViewBag.SearchObject IsNot Nothing Then
    m_Search = ViewContext.Controller.ViewBag.SearchObject
Else
    m_Search = ""
End If
End Code

<div>
    <div class="wrapperSearch">
         <input class="inputSearch" placeholder="Search..." type="text" id="searchValue" value="@m_Search" autocomplete="off">
    </div>
</div>

搜索的Jquery如下:

    $(document).ready(function () {
    var amountFilter = 0;

    $('#searchValue').on('keyup', function () {

        var filterText = $('#searchValue').val();
        var DepId = JSON.parse('@Html.Raw(Json.Encode(ViewData("ID")))');
        var filterTextLength = filterText.length;

        $("#log").ajaxError(function (event, jqxhr, settings, exception) {
            alert(exception);
        });

        var runIt = 'false';

        if (filterText.length > 2) {
            runIt = 'true';
        } else if (filterText.length == 0) {
            runIt = 'true';
        }

        if (runIt == 'true') {
            var existingUrl = window.location.href;
            var n = existingUrl.indexOf("/Gallery");
            if (n < 0) {
                var url = '@Url.Action("Gallery", "UX", New With {.id = "filter"})?search=' + filterText;
                window.location.href = url;
            }

            $.get('@Url.Action("GalleryPartial")',
                    { searchen: filterText, id: DepId, sort: "" }, function (data) {

                        $("#target").html(data);
                });

            SetupFilters();
        }
    }); 
}

在 Kusto 中,您可以使用多种辅助方法。在您的情况下 parse_url 可能会有所帮助,因为它将包含一组可以轻松访问的查询参数:

requests
| extend searchText = tostring(parse_url(url).["Query Parameters"]["search"])
| summarize count() by bin(timestamp, 1m), searchText 
| render timechart