Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

c# - AjaxfileUpload error

I'm trying to implement a simple ajaxtoolkit fileupload control and every time I click "Upload" all I get is an error. I tried placing breakpoint in the "AjaxFileUpload1_UploadComplete" function but it won't even get fired.. (maybe because upload isn't complete yet?) what should I do to make it work?

here is the error: enter image description here

here is my aspx:

 <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

       <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
            onuploadcomplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10" AllowedFileTypes="jpg,jpeg"/>

    </div>
    </form>

and here is the funcion behind:

protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string id = "038191904";
        Directory.CreateDirectory(Server.MapPath("~/App_Data/" + id + "/scanned_docs/"));
        string filePath = "~/Member_Data/" + id + "/images/";
        string path = filePath + e.FileName;
        AjaxFileUpload1.SaveAs(Server.MapPath(filePath) + e.FileName);

        //db1.insert_pic_slide(id, path);

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This was happening to me, and I did two things to fix it:

1) Update your site's web.config file to contain entries for the following:

<system.web>
  <httpHandlers>
    <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
  </httpHandlers>
</system.web>
<system.webServer>
  <handlers>
    <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
  </handlers>
</system.webServer>

2) If the page you're uploading from is inside a folder with it's own web.config with deny anonymous authorization rules, make sure you add an allow for the AjaxFileUploadHandler like so:

<location path="AjaxFileUploadHandler.axd">
  <system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...