You must Sign In to post a response.
  • Category: ASP.Net MVC

    Unable to access Webapi from one server from Angular app on another server


    I have my Webapi on one server say http://localhost:51989/

    and my Angular app is running on http://localhost:65307/

    I'm unable to call the api from my AngularApp, I'm getting 500 error due to my Api is not letting to access. although I can do successful get on my browser.

    Few things I did was:
    1. config.EnableCors(); in WebApiConfig.cs

    [EnableCors("http://localhost:65307/", "*", "*")]
    public class EventController : ApiController
    [EnableCorsAttribute("http://localhost:65307/", "*", "*")]
    public JToken Get(string id = null)
    [EnableCorsAttribute("http://localhost:65307/", "*", "*")]
    public void Post(string id, JObject eventData)

    3. in Providers/ApplicationOAuthProvider.cs

    public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)

    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin",new[] { "http://localhost:65307/" });}
  • #765638
    Can you please post a code about your angular api call. I am guessing that way you are making a api call from angularapp have some issue in it

  • #765653
    Web API is build for restful web service . It is very simple to make it and also it is very simple to call from any other application.
    I think the issue is in your calculation part of the wep api. Do one thing create one simple web api and try to access from your angular js or Jquery AJAX or C# code etc... If it is working fine then start your implementation of your requirement in that sample. So that you can easily identify the issue in the code.

    By Nathan
    Direction is important than speed

Sign In to post your comments