AjaxToolkit中的AjaxFileUpload不起作用

时间:2015-01-23 15:59:14

标签: c# asp.net ajaxcontroltoolkit

尝试上传文件时出现以下错误:

System.Web.HttpException在调用HttpRequest.Form,Files,InputStream或BinaryRead后,不支持此方法或属性。

调用堆栈是:

System.Web.HttpException (0x80004005): This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked.
  at System.Web.HttpRequest.GetInputStream(Boolean persistEntityBody, Boolean disableMaxRequestLength)
  at AjaxControlToolkit.AjaxFileUploadHelper.Process(HttpContext context)
  at AjaxControlToolkit.AjaxFileUploadHandler.ProcessRequest(HttpContext context)
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

App Pool配置为集成模式。 我正在使用Framework 4.5。 我正在使用最新版本的Ajax Toolkit。

在触发OnUploadComplete事件之前发生此错误。

以下是代码摘录......

摘录1:

<form id="Form1" class="theForm" enctype="multipart/form-data" runat="server">
    <atk:ToolkitScriptManager EnableHistory="true" ID="tsm" runat="server">
    ....
</form>

摘录2:

<ajaxToolkit:AjaxFileUpload ID="afuDoc" MaximumNumberOfFiles="1" OnUploadComplete="afuDoc_UploadComplete" ThrobberID="imgLoading"runat="server" />

摘录3:

protected void afuDoc_UploadComplete(Object sender, AjaxFileUploadEventArgs e)
{
    if (afuDoc.IsInFileUploadPostBack && e.State == AjaxFileUploadState.Success)
    {
        afuDoc.SaveAs(@"~/Uploads/" + e.FileName);
    }
}

extract 4(system.web中的Web.config):

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

extract 5(system.webServer中的Web.config):

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

提前致谢!

更新:

Elmah实际上发现了另一个错误以及上面提到的错误。第二个错误如下。

System.IO.DirectoryNotFoundException找不到路径的一部分&#39; C:\ Windows \ TEMP_AjaxFileUpload \ D8FC028F-3950-94BD-6205-8F2EF7DC43B7&#39;。

调用堆栈是:

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\TEMP\_AjaxFileUpload\D8FC028F-3950-94BD-6205-8F2EF7DC43B7'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption, Boolean checkHost)
   at System.IO.Directory.InternalGetFiles(String path, String searchPattern, SearchOption searchOption)
   at AjaxControlToolkit.AjaxFileUpload.XhrDone(String fileId)
   at AjaxControlToolkit.AjaxFileUpload.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.main_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\msdebug\3d598d4d\d90118d\App_Web_frmymo1s.1.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

0 个答案:

没有答案