C# 从客户端检测到一个潜在危险的请求。表单值(编辑器=“div id=”header“sty…”)
首先,我应该说我已经关注了下面的所有问题和论坛帖子 所有提到的在web.config文件中添加C# 从客户端检测到一个潜在危险的请求。表单值(编辑器=“div id=”header“sty…”),c#,asp.net-mvc,razor,rich-text-editor,richtextediting,C#,Asp.net Mvc,Razor,Rich Text Editor,Richtextediting,首先,我应该说我已经关注了下面的所有问题和论坛帖子 所有提到的在web.config文件中添加或的线程,但这对我不起作用 一旦我这样做并开始调试,就会出现这种错误 实际上,我正在尝试将HTML文件加载到富格文本编辑器内容中,然后单击“另存为PDF”按钮将富格文本编辑器内容保存到PDF文件中 这些是相关的控制器类方法 [ValidateInput(false)] public ActionResult output_xhtml() {
或
的线程,但这对我不起作用
一旦我这样做并开始调试,就会出现这种错误
实际上,我正在尝试将HTML文件加载到富格文本编辑器内容中,然后单击“另存为PDF”按钮将富格文本编辑器内容保存到PDF文件中
这些是相关的控制器类方法
[ValidateInput(false)]
public ActionResult output_xhtml()
{
PrepairEditor(delegate(Editor editor)
{
editor.LoadHtml("~/example.html");
});
return View();
}
[HttpPost]
[ValidateInput(false)]
public ActionResult output_xhtml(string m)
{
Editor theeditor = PrepairEditor(delegate(Editor editor)
{
});
theeditor.SavePDF("~/aaa.pdf");
return View();
}
PrepairEditor()方法
protectededitor-PrepairEditor(操作oninit)
{
编辑器编辑器=新编辑器(System.Web.HttpContext.Current,“编辑器”);
editor.ClientFolder=“/richtexteditor/”;
editor.ContentCss=“/Content/example.css”;
//editor.ClientFolder=“/Content/richtexteditor/”;
//editor.ClientFolder=“/Scripts/richtexteditor/”;
editor.Text=“在此处键入”;
editor.AjaxPostbackUrl=Url.Action(“EditorAjaxHandler”);
如果(oninit!=null)oninit(编辑器);
//尝试处理上传/ajax请求
bool isajax=editor.MvcInit();
if(isajax)
返回编辑器;
//加载表单数据(如果有)
if(this.Request.HttpMethod==“POST”)
{
string formdata=this.Request.Form[editor.Name];
if(formdata!=null)
编辑器.LoadFormData(formdata);
}
//将编辑器渲染到ViewBag.editor
ViewBag.Editor=Editor.MvcGetString();
返回编辑器;
}
//此操作由editor.AjaxPostbackUrl=Url.action(“EditorAjaxHandler”)指定;
//它将处理编辑器对话框Upload/Ajax请求
[验证输入(错误)]
公共操作结果EditorAjaxHandler()
{
PrepairEditor(代理(编辑器)
{
});
返回新的EmptyResult();
}
这是PrepairEditor()方法中发生错误的屏幕截图
输出xhtml.cshtml查看文件
<!DOCTYPE html>
<html>
<head>
<title>RichTextEditor - Output XHTML</title>
</head>
<body>
<script type="text/javascript">
var editor;
function RichTextEditor_OnLoad(editor) {
editor = editor;
var content = true;
if (!content) {
setTimeout(function () {
editor.SetText("<table>.....</table>");
}, 1000);
return;
}
}
</script>
<script type='text/javascript'>
function RichTextEditor_OnLoad(editor) {
editor.SetWidth(1150); //Sets the width.
editor.SetHeight(612); //Sets the height.
}
</script>
@using (Html.BeginForm())
{
<div>
@Html.Raw(ViewBag.Editor)
<br />
<button id="btn_sumbit" type="submit" class="btn btn-danger submit">Save as PDF</button>
</div>
<br />
<div>
<h3>
Result html:
</h3>
<div>
@ViewBag._content
</div>
</div>
}
</body>
</html>
RichTextEditor-输出XHTML
变量编辑器;
函数RichTextEditor\u OnLoad(编辑器){
编辑=编辑;
var内容=真;
如果(!内容){
setTimeout(函数(){
editor.SetText(“…”);
}, 1000);
返回;
}
}
函数RichTextEditor\u OnLoad(编辑器){
editor.SetWidth(1150);//设置宽度。
editor.SetHeight(612);//设置高度。
}
@使用(Html.BeginForm())
{
@Html.Raw(ViewBag.Editor)
另存为PDF
结果html:
@查看包。\u内容
}
这是因为您正在传递HTML
添加:[allowtml]
在方法上方
一旦我这样做并开始调试,就会出现这种错误
看看你得到的错误。您的web.config中已经有一个
部分。你不能有两个。更改现有的方法而不是添加新的方法。[AllowHtml]位于模型中的属性上,而不是控制器方法上。它的名称空间是System.Web.MVC哪个方法output\u xhtml()
或PrepairEditor()
?output\u xhtml()这是您将HTML发布到的方法。不,我曾经在[allowtml]下执行过一次geting red Swiggly lline错误
VS中的标记这是错误定义,那么属性“AllowHtml”在此声明类型上无效。它仅对“属性,索引器”声明有效。
在配置中使用此功能。阅读错误…是的,这是错误,我的错
<!DOCTYPE html>
<html>
<head>
<title>RichTextEditor - Output XHTML</title>
</head>
<body>
<script type="text/javascript">
var editor;
function RichTextEditor_OnLoad(editor) {
editor = editor;
var content = true;
if (!content) {
setTimeout(function () {
editor.SetText("<table>.....</table>");
}, 1000);
return;
}
}
</script>
<script type='text/javascript'>
function RichTextEditor_OnLoad(editor) {
editor.SetWidth(1150); //Sets the width.
editor.SetHeight(612); //Sets the height.
}
</script>
@using (Html.BeginForm())
{
<div>
@Html.Raw(ViewBag.Editor)
<br />
<button id="btn_sumbit" type="submit" class="btn btn-danger submit">Save as PDF</button>
</div>
<br />
<div>
<h3>
Result html:
</h3>
<div>
@ViewBag._content
</div>
</div>
}
</body>
</html>