/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Mvc/test/Mvc.FunctionalTests/Infrastructure/IHtmlDocumentExtensions.cs
41 строка
1 KB
Youssef Fahmy
Update AngleSharp to latest (#67898)
20 июл 2026, 15:48
Не верифицирован
20 июл 2026, 15:48
fc4e6e0
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using AngleSharp.Dom; using AngleSharp.Html.Dom; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public static class IHtmlDocumentExtensions { public static IElement RequiredQuerySelector(this IHtmlDocument document, string selector) { var element = document.QuerySelector(selector); if (element == null) { throw new ArgumentException($"Document does not contain element that matches the selector {selector}: " + Environment.NewLine + document.DocumentElement.OuterHtml); } return element; } public static string RetrieveAntiforgeryToken(this IHtmlDocument htmlDocument) { var hiddenInputs = htmlDocument.QuerySelectorAll("form input[type=hidden]"); foreach (var input in hiddenInputs) { if (!input.HasAttribute("name")) { continue; } var name = input.GetAttribute("name"); if (name == "__RequestVerificationToken" || name == "HtmlEncode[[__RequestVerificationToken]]") { return input.GetAttribute("value"); } } throw new Exception($"Antiforgery token could not be located in {htmlDocument.Source.Text}."); } }