I am calling an API (asp.net web api) from Angular 9 but sometimes I am getting Cross origin error. The debugger is hitting the API method and it returns the values as expected but in the browser I am getting 500 status with Access-Control-Allow-Origin header issue. Also this error does displays always only sometimes in particular for some particular responses. so can anyone help me here? Here are some sample codes.
[Route("api/product/Selection")]
[HttpPut()]
public IHttpActionResult Selection(VOW.Api.ProjectManager.Models.IndustrialSilencer product, string currency, string markup, string userTier2Markup, string projectId)
{
//some code
ISM.SelectOutput(ref output, product, currency, Convert.ToDouble(markup), Convert.ToDouble(userTier2Markup), projectInfo.ExchangeRate);
return Ok(output);
}
const S = this.http.put<Silencer>(this.baseurl + "/Selection", product, opts).subscribe(r => {
S.unsubscribe();
observer.next(r);
observer.complete();
},
e => {
S.unsubscribe();
observer.error(e); // because its not any http call
observer.complete();
},
() => {
S.unsubscribe();
}
);
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}