I develop a web application. Client side - Javascript/Typescript + AngularJS Server side - c# - asp.net web api 2 IIS Express as host.
I noticed a wierd issue occuring in which POST requets reach the server more than once. For example, one scenario in which requests are sent multiple times, each request for a specific folder email is sent 3 times. I also see those request sent three times in the Network tab.
public class mailsService extends ImailsService{
static instance : ImailsService;
// Dictionary of folder -> emails
public Folders;
public mailsService(){
var scope = this;
myInterval = setInterval(function(){
// Making this request until getting a successful response - waiting for server to go up
scope.webService.get("url to get my own place").success(data => {
scope.myLocation = data;
scope.isLocationInit = true;
getAllMails();
window.cleanInterval(myInterval);
})
}, 3000);
}
// This function happen on it's own when running the client code.
// The service is a singleton therefore this code runs only once.
public getAllMails() {
if (!this.isLocationInit)
return;
var scope = this;
scope.webService.get("url to get all folders").then(reponse => {
var folders = response.data;
for (var i = 1; i <= folders.length; i ++){
return scope.get("url to get the mails inside specific folder").then(initMails.bind(null, i));
}});
}
public initMails (folderId : number, response){
mailsService.instance.Folders[folderId].push(response.data);
}
}
public class webService extends IwebService {
public get(url : string){
return this.$http.get(url);
}
public post(url : string, data : any){
return this.$http.post(url, data);
}
}
// Server side:
// Cross-Origin requests
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class MailsController : ApiController
{
private IMailsService _mailsService;
public MailsController(IMailsService service)
{
this._mailsService = service;
}
public IHttpActionResult GetAllFolders()
{
var result = _mailsService.GetAllFolders();
if (result == null)
return BadRequest("...");
return Ok(result);
}
public IHttpActionResult GetFolderEmails(int folderId)
{
var result = _mailsService.GetFolderEmails(folderId);
if (result == null)
return BadRequest("...");
return Ok(result);
}
}
The controller fitting method hits twice or even more, although it is called only once from the cliend side code.
Is this something configurably? IIS wierd thing? I seriously don't know where to start looking.