Return the error from CustomHttpHandler

3 posts, 1 answers
  1. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 17 Jul 2014 Link to this post

    Hi
    I am using Radasyncupload and using a customhttphandler and saving files directly to the database. Sometimes the handler is failing because of some error in the code like DB is not available or someother error  and I want to return the exact error message to the application. How can I accomplish this? Any help is much appreciated.

    Thanks
    Rakesh
  2. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 22 Jul 2014 Link to this post

    Hi Rakesh,

    Handle the error in the Handler and return custom result.
    protected override IAsyncUploadResult Process(UploadedFile file, HttpContext context, IAsyncUploadConfiguration configuration, string tempFileName)
     {
         // Call the base Process method to save the file to the temporary folder
         // base.Process(file, context, configuration, tempFileName);
     
         // Populate the default (base) result into an object of type SampleAsyncUploadResult
         SampleAsyncUploadResult result = CreateDefaultUploadResult<SampleAsyncUploadResult>(file);
     
         int userID = -1;
         // You can obtain any custom information passed from the page via casting the configuration parameter to your custom class
         SampleAsyncUploadConfiguration sampleConfiguration = configuration as SampleAsyncUploadConfiguration;
         if (sampleConfiguration != null)
         {
             userID = sampleConfiguration.UserID;
         }
           
         // Populate any additional fields into the upload result.
         // The upload result is available both on the client and on the server
         result.ImageID = InsertImage(file, userID);
           
         return result;
     }

    Similar to this online demo:
    http://demos.telerik.com/aspnet-ajax/asyncupload/examples/imageuploader/defaultcs.aspx

    I hope this helps.

    Regards,
    Hristo Valyavicharski
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rakesh
    Rakesh avatar
    23 posts
    Member since:
    May 2013

    Posted 20 Aug 2014 in reply to Hristo Valyavicharski Link to this post

    Thank you. It worked
Back to Top