Last post Jul 02, 2014 02:20 AM by DevinderYadav
Jul 01, 2014 03:26 AM|DevinderYadav|LINK
I am consuming a wcf service. When I am allow cross origin in web.config Then I am able to get the data but not able to post the data. When I allow cross origin in glopal.ascx then able to post the data. If I remove cross origin from web.config. Then I am
not able to get the data from service if cross origin alloweded in both the files then it starts giving error duplicate header allo cross origin *. but that thing working properly on localhost when the wcf is hosted then it is creating the problem.
Please help guys, It's urgent.
Jul 01, 2014 10:32 PM|Fuxiang Zhang - MSFT|LINK
Thanks for your post.
If we want our wcf service can be called by ajax cross domain, there two options we can choose.
# Configing the web.config like below.
<modules runAllManagedModulesForAllRequests="true" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
# Or we can do it in the global.asax file like below.
protected void Application_BeginRequest(object sender, EventArgs e)
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin" , ”*”);
if (HttpContext.Current.Request.HttpMethod == "OPTIONS" )
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods" , "GET, POST" );
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers" , "Content-Type, Accept" );
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age" "1728000" );
Code comes from below article, you can refer it from below.
Hope this helps, thanks.
Jul 02, 2014 02:20 AM|DevinderYadav|LINK
Thanks For you quick reply But I tried both the thing yesterday my code is not working properly . But today it's working properly. I don't know what is the problem but it's working.