如何通过 Helper 方法在 ASP.NET MVC 布局上使用 CSP 值
通过 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论