简体   繁体   中英

ASP Web API call to /Token intermittent

Since I have deployed my app to a test environment, the calls to /Token (to log in and get a token) are playing up. The problem is it won't work at all for a few calls (takes 30 seconds and then returns a 500 error), then all of a sudden it will just start working (and working flawlessly, get a reply in <50ms).

On localhost on the dev machine, it has never skipped a beat.

My dev setup was just on localhost; my test setup has three servers - one for the html/js and an iis rewrite which points to the second server which hosts the APIs and a third DB server.

Same response via the following javascript:

        var loginData = {
        grant_type: 'password',
        username: self.loginEmail(),
        password: self.loginPassword()
    };

    $.ajax({
        type: 'POST',
        url: url + '/Token',
        data: loginData
    }).done(function (data) {
        self.loggedInUserName(data.userName);
        // Cache the access token in session storage.
        sessionStorage.setItem(tokenKey, data.access_token);

Or if I use POSTMAN I get the same response.

Web.config:

  <system.webServer>
<httpErrors errorMode="Detailed" />
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule"/>
</modules>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
  </customHeaders>
</httpProtocol>

Also I have put the following:

            GlobalConfiguration.Configuration.IncludeErrorDetailPolicy
        = IncludeErrorDetailPolicy.Always;

in my Global.asax file but error messages still aren't showing (wonder if this is the IIS rewrite hiding them?)

EDIT: all calls to /api work flawlessly, it's only /Token that's playing up.

Ah what a silly problem.

Detailed errors were not working as it was going via the IIS rewrite. I started hitting the API directly and the errors were showing which was "network path not found".

Turns out I had the DNS of the DB server connecting to the wrong IP (the non-domain joined one). I still think it's strange it was intermittent but it seems to be working now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM