asp.net 尝试在html编辑器扩展程序中插入图像

mmvthczy  于 2023-02-01  发布在  .NET
关注(0)|答案(4)|浏览(135)

我正在尝试将图像插入到html编辑器扩展程序中。

<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" EnableSanitization="false" 
    OnImageUploadComplete="HtmlEditorExtender1_ImageUploadComplete"
     TargetControlID="TextBoxBody">
    <Toolbar> 
                <ajaxToolkit:Undo />
                <ajaxToolkit:Redo />
                <ajaxToolkit:Bold />
                <ajaxToolkit:Italic />
                <ajaxToolkit:Underline />
                <ajaxToolkit:StrikeThrough />
                <ajaxToolkit:Subscript />
                <ajaxToolkit:Superscript />
                <ajaxToolkit:JustifyLeft />
                <ajaxToolkit:JustifyCenter />
                <ajaxToolkit:JustifyRight />
                <ajaxToolkit:JustifyFull />
                <ajaxToolkit:InsertOrderedList />
                <ajaxToolkit:InsertUnorderedList />
                <ajaxToolkit:CreateLink />
                <ajaxToolkit:UnLink />
                <ajaxToolkit:RemoveFormat />
                <ajaxToolkit:SelectAll />
                <ajaxToolkit:UnSelect />
                <ajaxToolkit:Delete />
                <ajaxToolkit:Cut />
                <ajaxToolkit:Copy />
                <ajaxToolkit:Paste />
                <ajaxToolkit:BackgroundColorSelector />
                <ajaxToolkit:ForeColorSelector />
                <ajaxToolkit:FontNameSelector />
                <ajaxToolkit:FontSizeSelector />
                <ajaxToolkit:Indent />
                <ajaxToolkit:Outdent />
                <ajaxToolkit:InsertHorizontalRule />
                <ajaxToolkit:HorizontalSeparator />
                <ajaxToolkit:InsertImage />
                </Toolbar>
    </ajaxToolkit:HtmlEditorExtender>

以及上载完成时的方法

protected void HtmlEditorExtender1_ImageUploadComplete(object sender, AjaxFileUploadEventArgs e)
    {
        string fullpath = Server.MapPath("~/Eventimg/") + e.FileName;
        var ajaxFileUpload = (AjaxFileUpload)sender;
        HtmlEditorExtender1.AjaxFileUpload.SaveAs(fullpath);
        e.PostedUrl = Page.ResolveUrl("~/Eventimg/" + e.FileName);
    }

但在文件上传窗口,我得到这个:文件名.jpg(错误)上传100%我做错了什么?你的帮助将被appriciated。. Thanx

7uzetpgm

7uzetpgm1#

需要将此节点添加到中。

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
  <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</handlers>
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="4294967295"/>
  </requestFiltering>
</security>

并将此节点添加到您的站点:

<httpHandlers>
  <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</httpHandlers>

作者:“威尔·邵”

q1qsirdb

q1qsirdb2#

您正在错误地访问SaveAs。请使用以下命令:

protected void HtmlEditorExtender1_ImageUploadComplete(object sender, AjaxFileUploadEventArgs e)
{
    string fullpath = Server.MapPath("~/Eventimg/") + e.FileName;
    var ajaxFileUpload = (AjaxFileUpload)sender;
    //HtmlEditorExtender1.AjaxFileUpload.SaveAs(fullpath);
    ajaxFileUpload.SaveAs(fullpath);
    e.PostedUrl = Page.ResolveUrl("~/Eventimg/" + e.FileName);
}
5vf7fwbs

5vf7fwbs3#

我发现如果你把QueryString传递到页面,你会得到一个上传错误。很长一段时间我都不知道我做错了什么。然后我改变了我的页面逻辑-使用Cookie/会话变量而不是QueryString-宾果,它起作用了!奇怪,但真的...

c86crjj0

c86crjj04#

我做了所有这些建议,但没有成功,除非我也改变了打开我的编辑器页面的方式从Server.Transfer(...)Response.Redirect(...)
我花了几个小时才弄明白这个。也许别人觉得有用:-)

相关问题