3

There are lots of question like my question but I didn't any working solution.

I am using AngularJS and WebApi2 in my application.

Here is the JS code which call the initial API.

(function (module) {
var baseUrl= "http://localhost:85";
module.constant('Config', baseUrl);
module.service('identities', ['$http', function ($http) {
    var uri = baseUrl+ '/api/controller/GetRole';

    var identities = {};
    identities.get = function () {
        var temp = $http.get(uri);
        console.log(temp, "identities");
        return temp;
    }
    return identities;
}]); 

This function call the GetRole method in web API controller to retrieve user role.The output of this method is JSON with user details.

I have deployed the application on a server to port 85. When I run the application it's throwing error in Chrome:

net::ERR_CONNECTION_REFUSED

and in IE 11:

XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd

There is no log created in IIS for this request.

Using fiddler I got this in Raw with status code 502 in response. The connection to 'localhost' failed.

Error: ConnectionRefused (0x274d).

System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:85.

I have also tried by disabling the CORS in chrome but no luck. IF I use IP address of server instead of localhost as baseUrl in angular JS code then it's working fine. Why it's not working with localhost?

I am doing a GET call and Error for me is 00002efd not 00002ef3.

Community
  • 1
  • 1
hotam kushwah
  • 51
  • 1
  • 5
  • Possible duplicate of [SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3, Could not complete the operation due to error 00002ef3](http://stackoverflow.com/questions/14527387/script7002-xmlhttprequest-network-error-0x2ef3-could-not-complete-the-operati) – blurfus Jul 11 '16 at 23:03
  • I already check that but no luck, for me its Get call not Post Call and error is "Error 0x2efd". – hotam kushwah Jul 12 '16 at 05:15
  • You need to enable CORS in the web api. Install Install-Package Microsoft.AspNet.WebApi.Cors. Add "config.EnableCors();" to the WebApiConfig.cs Register method – Marcus Höglund Jul 12 '16 at 05:35
  • while installing package it gives: Install-Package : Unable to load the service index for source https://api.nuget.org/v3/index.json. At line:1 char:16 + Install-Package <<<< Microsoft.AspNet.WebApi.Cors + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand When I run Get-Package -ListAvailable then there is no such package available. I am using vs2015. – hotam kushwah Jul 12 '16 at 11:15

0 Answers0