Wednesday 26 December 2018

Error: No ‘Access-Control-Allow-Origin’ Header is Present – Origin ‘localhost:…’ is therefore not allowed access

If you are using .net web api and again and again you build your's project and run that you will see that your's runs on different port after running you will be get following error in console window

Error: No ‘Access-Control-Allow-Origin’ Header is Present – Origin ‘localhost:…’ is therefore not allowed access.



this is very comman issue which can stuck  the developer in web api 
you can remove this by just configure the Global.asax file in Application_BeginRequest section  

by the following code in which we just configure the header section of the service


protected void Application_BeginRequest(object sender, EventArgs e){
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin","*"")
}

No comments:

Post a Comment

AdSense

The Ultimate Guide to Interceptors: Understanding Their Power and Functionality

  The Ultimate Guide to Interceptors: Understanding Their Power and Functionality An interceptor is a service that can intercept HTTP reques...

Follow