c# - ASP.NET Web API "400 Bad Request" on POST Request When Deploying to Test Server -


i have single page application (spa) angularjs front-end , .net web api backend. works fine on development machine, i.e. when run visual studio (2015) under localhost. however, once published our testing server, when sending post requests web api "400 bad request" error. requests work fine. debugging fiddler , when in textview tab says "the underlying provider failed open". here screenshots fiddler:

this how request , response on local machine:

loaclhost response headers

this response headers on the test server:

test server response headers

and textview on test server:

test server response text view

the data being sent through post request same both localhost , test server. also, both of them authorization header present. other values "referer" , "host", other difference noticing between them localhost running on iis/10.0 while test server on iis/8.0.

the code angularjs resource calls webapi following:

(function () { "use strict";  angular     .module("mainapp")     .factory("incidentresource", ["$resource", "baseapiurl", incidentresource]);  /// factory function. angular $resource service , appsettings /// constant injected parameters. function incidentresource($resource, baseapiurl) {      return {          generatefile: $resource(baseapiurl + "/api/imports/previewoverlay", null,         {             'generate': { method: 'post' }         })      }; }  })(); 

this called angular code so:

vm.generate = function () {         incidentresource.generatefile.generate(vm.divisionimports,             function (data) {                 vm.successmessage.show = true;             },              function (response) {                 vm.message = response.statustext + "\r\n";                 if (response.data.exceptionmessage) {                   vm.message += response.data.exceptionmessage;                 }             });     } 

and finally, web api controller looks this:

[routeprefix("api/imports")] public class importcontroller : basecontroller {     [authorize]     [httppost]     [route("previewoverlay")]     public ihttpactionresult generatefile(divisionimport[] chargedincidents)     {         try         {             // name of user logged in             string username = this.getcurrentuseridfromrequest();              list<divisionimport> incidentslist = new list<divisionimport>();              incidentslist.addrange(chargedincidents);              this.incidentfilebuilder.generatefile(filetype.delimited, incidentslist);              return this.ok();         }         catch (exception ex)         {             return this.badrequest(ex.message);         }     } }  [enablecors(origins: "*", headers: "*", methods: "*")] public class basecontroller : apicontroller { } 

what causing error?

as @dan jul pointed out, error caused faulty database connection string. while deploying code our test server, changed connection configuration file different 1 (for test server) , contained connection string syntax error.

things working now.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -