Anyway to bypass the UploadHandler.ashx completely?

Last post 01-11-2011, 9:12 PM by cutechat. 1 replies.
Sort Posts: Previous Next
  •  12-27-2010, 11:03 PM 65537

    Anyway to bypass the UploadHandler.ashx completely?

    I am wondering if there is a way to bypass the ashx file altogether?  I cannot seem to get rid of this file without causing major errors even though I am not using it really.  I am assuming that it is primarily using the GetValidateOption() function from that file since Everything else I am doing is through the controller. 
     
    Thanks
    Filed under:
  •  01-11-2011, 9:12 PM 65685 in reply to 65537

    Re: Anyway to bypass the UploadHandler.ashx completely?

    Hi,
     
    You can bypass the UploadHandler.ashx , but mvc uploader still need a url to handle the stream and validate the uploaded file.
     
    The upload handler code is simple , you can implement your self  .
     
    And change the uploader.UploadUrl to your handler url or just your controller.
     
     
      void IHttpHandler.ProcessRequest (HttpContext context)
      {
       using (_uploader = new MvcUploader(context))
       {
        UploaderValidateOption option=this.GetValidateOption();
        _uploader.MaxSizeKB=option.MaxSizeKB;
        _uploader.AllowedFileExtensions=option.AllowedFileExtensions;
        OnUploaderInit(_uploader);
       
        _uploader.PreProcessRequest();
        if (!_uploader.IsValidationRequest)
         return;
        
        try
        {
         _file = _uploader.GetValidatingFile();
        
         OnFileUploaded(_file);
        }
        catch(Exception x)
        {
         _uploader.WriteValidationError(x.Message,_data);
         return;
        }
        
        _uploader.WriteValidationOK(_data);
       }
      }
     
     
    the core thing is PreProcessRequest,WriteValidationError,WriteValidationOK
     
     
    Regards,
    Terry
     
     
     
View as RSS news feed in XML