我如何在全球范围内设置自定义的htmlencoder以在所有剃须刀页面中使用?
我想设置一个自定义htmlencoder
为默认htmlencoder
要在ASP.NET Core Razor页面中使用。
razorPageBase 类确实具有
htmlencoder
属性,我可以在单个剃须刀页面上设置该属性:
using System.Text.Encodings.Web;
using System.Text.Unicode;
@{
HtmlEncoder = HtmlEncoder.Create(UnicodeRanges.All);
}
然后在该页面上使用htmlencoder
。
现在要尝试的显而易见的是将此代码应用于'viewStart.cshtml':
using System.Text.Encodings.Web;
using System.Text.Unicode;
@{
Layout = "_Layout";
HtmlEncoder = HtmlEncoder.Create(UnicodeRanges.All);
}
但是,这仍然不起作用,它仍然使用默认htmlencoder
(它填充了良好,并且确实选择了布局属性)。
这意味着,要为所有页面设置默认htmlencoder
,我必须将上面的代码包括到每个剃须刀页面,包括每个部分页面,当然还有“ _layout.cshtml”。
我希望我错过了什么。
我该如何在全球范围内指定它,因此它适用于所有剃须刀页面?
I want to set a custom HtmlEncoder
as the default HtmlEncoder
to be used in Asp.net Core Razor pages.
The RazorPageBase
class does have a HtmlEncoder
property which I can set on a single Razor page like this:
using System.Text.Encodings.Web;
using System.Text.Unicode;
@{
HtmlEncoder = HtmlEncoder.Create(UnicodeRanges.All);
}
Then the HtmlEncoder
is used on that page.
Now the obvious thing to try is to apply this code to 'ViewStart.cshtml':
using System.Text.Encodings.Web;
using System.Text.Unicode;
@{
Layout = "_Layout";
HtmlEncoder = HtmlEncoder.Create(UnicodeRanges.All);
}
However, this does not work, it still uses the default HtmlEncoder
(it compiles fine and it does pick up the Layout property).
This means, that to set the default HtmlEncoder
for all pages, I have to include the code above to each and every Razor page, including each and every Partial page and of course "_Layout.cshtml".
I hope I have missed something.
How can I specify this on a global scale so it applies to all Razor pages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的应用程序配置中,执行以下操作:
或
In your app configuration, do the following:
Or