Он выглядит так:
Код: Выделить всё
[HtmlTargetElement("script")]
public class ScriptTagHelper(IHttpContextAccessor httpContextAccessor) : TagHelper
{
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var httpContext = _httpContextAccessor.HttpContext;
// This is set in Program.cs
if (httpContext?.Items["CSP-Nonce"] is string nonce)
{
output.Attributes.SetAttribute("foo", "bar");
output.Attributes.SetAttribute("nonce", "blah" /*new HtmlString(nonce)*/);
}
}
}
Теги встроенных скриптов не получают ни одного атрибута. Изменить: Это произошло потому, что встроенные скрипты, которые я проверял, были из части, к которой применялся другой _ViewImports.
Итак, я вижу следующее:< /p>
Код: Выделить всё
...
Какой совет?
Подробнее здесь: https://stackoverflow.com/questions/792 ... bute-value