c# - ASP.NET MVC 4 File Upload via Ajax Error Logging -


i have ajax call:

$.ajax({                                             type: "post",                                             url: '/home/upload?customerid=' + customerid + "&questionid=" + id + "&community=" + communityselected + "&lot=" + lotselected,                                             data: formdata,                                             datatype: 'json',                                             contenttype: false,                                             processdata: false,                                             success: function (response) {                                                 alert('success!!');                                                 $("#" + id).attr('disabled', false);                                             },                                             error: function (error) {                                                 alert(error);                                                 console.log(error);                                             }                                         }); 

which calls this:

[httppost]         public actionresult upload(int customerid, int questionid, string community, int lot)         {              (int = 0; < request.files.count; i++)             {                      var file = request.files[i];                      string path = path.combine(server.mappath("~/uploadedfiles"),                                                    path.getfilename(customerid + "-" + community + lot + "-" + questionid + "-" + file.filename));                      file.saveas(path);              }              return json(new { success = true },             "text/plain");          } 

now works on localhost, when put on server , try upload file, 500 error. trying add error logging on .net side see problem is, question how adjust .net method show me error.

i tried try , catch so:

[httppost]         public actionresult upload(int customerid, int questionid, string community, int lot)         {              (int = 0; < request.files.count; i++)             {                 try                 {                      var file = request.files[i];                      string path = path.combine(server.mappath("~/uploadedfiles"),                                                    path.getfilename(customerid + "-" + community + lot + "-" + questionid + "-" + file.filename));                      file.saveas(path);                 }                 catch (exception e)                 {                     console.write(e);                 }              }              return json(new { success = true },             "text/plain");          } 

but how display error?

thanks,

without doing major changes simplest thing write text file:

system.io.file.writealltext(@"c:\somefolder\error.txt", text); 

make sure site can write folder tho.

there more options on how write text file on msdn.

(but should @ building proper error handling , reporting app, e.g. elmah below.)


if possible rethrow exception, ysod display.

catch (exception e) {     throw; } 

elmah option error logging.

e.g.

catch(exception e) {     elmah.errorsignal.fromcurrentcontext().raise(e); } 

see also, how use elmah manually log errors.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -