如何通过 Helper 方法在 ASP.NET MVC 布局上使用 CSP 值

发布于 2025-01-10 19:12:56 字数 466 浏览 3 评论 0原文

通过 ASP.NET Core,我提供了严格的内容安全策略。但我需要根据布局上的值设置在中间件上使用的随机数键值。 我想编写一个Helper方法,但是如何将布局上的“nonceContainer”id值获取到该方法中。我该怎么做?

    public static HtmlString NonceKey(this IHtmlHelper helper)
    {

        string nonceValue = helper.ViewContext.HttpContext.Items["nonce-key"].ToString();
        return new HtmlString(nonceValue);
    }

我想在辅助方法中使用此值

With ASP.NET Core, I provide strict content security policy. But I need to set the nonce key value that I use on the middleware from the value on the layout. I want to write a Helper method, but how can I get the "nonceContainer" id value on the Layout into the method. How can i this?

    public static HtmlString NonceKey(this IHtmlHelper helper)
    {

        string nonceValue = helper.ViewContext.HttpContext.Items["nonce-key"].ToString();
        return new HtmlString(nonceValue);
    }

I want to this value within Helper Method

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文