<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CORS &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/cors/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:23:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>CORS &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Azure CDN with Azure Web App &#8211; Access to Font at CDN has been Blocked by CORS Policy</title>
		<link>https://mail.sibeeshpassion.com/azure-cdn-with-azure-web-app-access-to-font-at-cdn-has-been-blocked-by-cors-policy/</link>
					<comments>https://mail.sibeeshpassion.com/azure-cdn-with-azure-web-app-access-to-font-at-cdn-has-been-blocked-by-cors-policy/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 14 Aug 2020 09:36:34 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure CDN]]></category>
		<category><![CDATA[Azure CDN WordPress CORS issue]]></category>
		<category><![CDATA[Azure CORS issue]]></category>
		<category><![CDATA[Azure web app]]></category>
		<category><![CDATA[CORS]]></category>
		<category><![CDATA[CORS with Azure CDN]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14177</guid>

					<description><![CDATA[[toc] Introduction Working with Azure web app is always fun. I was facing a CORS issue in my WordPress web application recently. Here in this post, I am going to share with you the solution that helped me. I was using Azure CDN to serve all my files and all the files were loading fine except the fonts and icons because I was getting the CORS issue. Here is the fix. Preceding is the image of my browser console, where you can see the error clearly. Here is how my blog looked like when the icons were not loading. Fix [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>Working with Azure web app is always fun. I was facing a CORS issue in my WordPress web application recently. Here in this post, I am going to share with you the solution that helped me. I was using Azure CDN to serve all my files and all the files were loading fine except the fonts and icons because I was getting the CORS issue. Here is the fix. Preceding is the image of my browser console, where you can see the error clearly.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="491" src="/wp-content/uploads/2020/08/CORS-error-in-broswser-console-1024x491.png" alt="" class="wp-image-14178" srcset="/wp-content/uploads/2020/08/CORS-error-in-broswser-console-1024x491.png 1024w, /wp-content/uploads/2020/08/CORS-error-in-broswser-console-300x144.png 300w, /wp-content/uploads/2020/08/CORS-error-in-broswser-console-768x368.png 768w, /wp-content/uploads/2020/08/CORS-error-in-broswser-console-425x204.png 425w, /wp-content/uploads/2020/08/CORS-error-in-broswser-console.png 1064w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>CORS issue</figcaption></figure>



<p>Here is how my blog looked like when the icons were not loading.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="785" height="258" src="/wp-content/uploads/2020/08/Missing-icons.png" alt="" class="wp-image-14181" srcset="/wp-content/uploads/2020/08/Missing-icons.png 785w, /wp-content/uploads/2020/08/Missing-icons-300x99.png 300w, /wp-content/uploads/2020/08/Missing-icons-768x252.png 768w, /wp-content/uploads/2020/08/Missing-icons-425x140.png 425w" sizes="(max-width: 785px) 100vw, 785px" /><figcaption>Missing icons</figcaption></figure>



<h2 class="wp-block-heading">Fix for &#8220;Acces to font CROS policy issue&#8221;</h2>



<p>The first thing to do is to allow requests from all the origins, we can easily do this in Azure web application. Just login to your Azure portal, and go to your Azure web application. Click on the CORS menu under API and * as the allowed origin. </p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="848" src="/wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app-1024x848.png" alt="" class="wp-image-14179" srcset="/wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app-1024x848.png 1024w, /wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app-300x249.png 300w, /wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app-768x636.png 768w, /wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app-425x352.png 425w, /wp-content/uploads/2020/08/Allow-origins-in-Azure-web-app.png 1137w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Allow origins in Azure web app</figcaption></figure>



<p>When you are done, just click on the Save button. </p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>By default files with .woff2, .woff, and .ttf extensions are not served by IIS in Azure App Service.</p><cite>Azure app service IIS config</cite></blockquote>



<p>Now we should edit our web.config file with the configuration for these files. The web.config file will be present in the root folder where your index file is. You can use windows explorer to FTP to get this file or use FTP clients such as FileZilla or use the deployment tool Kudu in the Azure portal.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="924" height="393" src="/wp-content/uploads/2020/08/Web.config-in-KUDU.png" alt="" class="wp-image-14180" srcset="/wp-content/uploads/2020/08/Web.config-in-KUDU.png 924w, /wp-content/uploads/2020/08/Web.config-in-KUDU-300x128.png 300w, /wp-content/uploads/2020/08/Web.config-in-KUDU-768x327.png 768w, /wp-content/uploads/2020/08/Web.config-in-KUDU-425x181.png 425w" sizes="(max-width: 924px) 100vw, 924px" /></figure>



<p> There should be separate configuration entries for each font file types. We will add these configurations in the system.webServer tag which is the child tag of configuration tag. </p>



<script src="https://gist.github.com/SibeeshVenu/a4bc9422db0ba1be7423b97beabf330d.js"></script>



<p>You can also do this by adding the extension called &#8220;Enable Static Web Fonts&#8221;. To add an extension, click on the Extensions menu from the left pan and then click on +Add.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="893" height="401" src="/wp-content/uploads/2020/08/Add-extension-in-Azure-app.png" alt="" class="wp-image-14182" srcset="/wp-content/uploads/2020/08/Add-extension-in-Azure-app.png 893w, /wp-content/uploads/2020/08/Add-extension-in-Azure-app-300x135.png 300w, /wp-content/uploads/2020/08/Add-extension-in-Azure-app-768x345.png 768w, /wp-content/uploads/2020/08/Add-extension-in-Azure-app-420x190.png 420w, /wp-content/uploads/2020/08/Add-extension-in-Azure-app-425x191.png 425w" sizes="(max-width: 893px) 100vw, 893px" /><figcaption>Add extension in Azure app</figcaption></figure>



<p>Now click on the &#8220;Choose extension&#8221; option and select the &#8220;Enable Static Web Fonts&#8221; extension.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1023" height="381" src="/wp-content/uploads/2020/08/Enable-static-web-fonts-extension.png" alt="" class="wp-image-14183" srcset="/wp-content/uploads/2020/08/Enable-static-web-fonts-extension.png 1023w, /wp-content/uploads/2020/08/Enable-static-web-fonts-extension-300x112.png 300w, /wp-content/uploads/2020/08/Enable-static-web-fonts-extension-768x286.png 768w, /wp-content/uploads/2020/08/Enable-static-web-fonts-extension-425x158.png 425w" sizes="(max-width: 1023px) 100vw, 1023px" /><figcaption>Enable static web fonts extension</figcaption></figure>



<p>Now accept the legal terms and click OK.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>When you are done configuring, just visit your azure web application, you should now see that all the fonts, icons are loaded.</p>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think which is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/azure-cdn-with-azure-web-app-access-to-font-at-cdn-has-been-blocked-by-cors-policy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Fix To No Access-Control-Allow-Origin header is present Or Working With Cross Origin Request In Asp Net Web API</title>
		<link>https://mail.sibeeshpassion.com/fix-to-no-access-control-allow-origin-header-is-present-or-working-with-cross-origin-request-in-asp-net-web-api/</link>
					<comments>https://mail.sibeeshpassion.com/fix-to-no-access-control-allow-origin-header-is-present-or-working-with-cross-origin-request-in-asp-net-web-api/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 11 Mar 2016 09:28:29 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Configure Web API In IIS]]></category>
		<category><![CDATA[CORS]]></category>
		<category><![CDATA[Cross Origin Request In Asp Net Web API]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[No Access-Control-Allow-Origin]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11345</guid>

					<description><![CDATA[[toc] Introduction In this article we are going to few possible fixes we can apply when we get an error &#8220;Response to the preflight request doesn&#8217;t pass access control check: No &#8216;Access-Control-Allow-Origin&#8217; header is present on the requested resource. Origin &#8216;http://localhost:58018&#8217; is therefore not allowed access&#8221;. We get this error when we are trying to get some data from another origin may be via an AJAX call. In this post, we will discuss the solutions for this error in detail and we will also discuss Cross Origin Requests. Here I am going to use Visual Studio 2015, Web API 2. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In this article we are going to few possible fixes we can apply when we get an error &#8220;Response to the preflight request doesn&#8217;t pass access control check: No &#8216;Access-Control-Allow-Origin&#8217; header is present on the requested resource. Origin &#8216;http://localhost:58018&#8217; is therefore not allowed access&#8221;. We get this error when we are trying to get some data from another origin may be via an <a href="http://sibeeshpassion.com/tag/ajax/" target="_blank" rel="noopener">AJAX </a>call. In this post, we will discuss the solutions for this error in detail and we will also discuss Cross Origin Requests. Here I am going to use <a href="http://sibeeshpassion.com/category/visual-studio/" target="_blank" rel="noopener">Visual Studio</a> 2015, Web API 2. I hope you will like this.</p>
<h2><strong>Background</strong></h2>
<p>I hosted my <a href="http://sibeeshpassion.com/category/web-api" target="_blank" rel="noopener">Web API</a> in a server, and what that API does is, it will just return the data in <a href="http://sibeeshpassion.com/tag/JSON/" target="_blank" rel="noopener">JSON </a>format. But when I try to consume this Web API via an Ajax call, I was getting the error &#8220;No &#8216;Access-Control-Allow-Origin&#8217; header is present on the requested resource&#8221;. I solved the same issues in different ways. Here I am going to share those.</p>
<h2><strong>Using the code</strong></h2>
<p>I assume that you have created a Web API and hosted it in your server. If you are new to Web API, you can always get some information from here <a href="http://sibeeshpassion.com/category/web-api" target="_blank" rel="noopener">Articles Related To Web API </a>.</p>
<p>We all will have some situations where we need to fetch some data from another domain or another site, right? If it is from the same site, you won&#8217;t be facing any issues at all. Like you are calling an Ajax call from the page www.sibeeshpassion.com/Receiver.html to www.sibeeshpassion.com/Sender.html to get the data, here the origin is same. and therefore you will get the data. What happens is when the sender and receiver are not in the same origin. Like you need to get the data from www.Microsoft.com by an Ajax call in www.sibeeshpassion.com/Receiver.html. The browser will not allow you to get the sensitive data from other domain, for the security purpose your browser will return you &#8220;No &#8216;Access-Control-Allow-Origin'&#8221;. To overcome this, we have something called Cross-Origin Resource Sharing (CORS). Basically, the process of allowing other sites to call your Web API is called CORS. According to <a href="https://www.w3.org/TR/cors/" target="_blank" rel="noopener">W3 Org</a> CORS is a standard which tells the server to allow the calls from other origins given. It is much secured than using JSONP(Previously we had been using JSON for getting the data from other domains.).</p>
<h3><strong>Fix To No Access-Control-Allow-Origin header is present</strong></h3>
<p>We can fix this issue in two ways,</p>
<ul>
<li>By using Microsoft.AspNet.WebApi.Cors</li>
<li>By adding header information in Web.config</li>
</ul>
<p>We will explain both now.</p>
<h3><strong>By using Microsoft.AspNet.WebApi.Cors</strong></h3>
<p>To work with this fix, you must include the package By using <em>Microsoft.AspNet.WebApi.Cors</em> from Manage Nuget window.</p>
<p><div id="attachment_11346" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package.png"><img decoding="async" aria-describedby="caption-attachment-11346" class="size-large wp-image-11346" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-1024x342.png" alt="CORS_In_Manage_NuGet_Package" width="634" height="212" srcset="/wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-1024x342.png 1024w, /wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-300x100.png 300w, /wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-768x257.png 768w, /wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-400x134.png 400w, /wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package-1795x600.png 1795w, /wp-content/uploads/2016/03/CORS_In_Manage_NuGet_Package.png 1861w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-11346" class="wp-caption-text">CORS_In_Manage_NuGet_Package</p></div></p>
<p>Now got to App_Start folder from your solution. Then click on the file <em>WebApiConfig.cs</em>, this is the file where we set the configuration for our Web API.</p>
<p><div id="attachment_11347" style="width: 308px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Web_API_Config_Class_File.png"><img decoding="async" aria-describedby="caption-attachment-11347" class="size-full wp-image-11347" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Web_API_Config_Class_File.png" alt="Web_API_Config_Class_File" width="298" height="221" /></a><p id="caption-attachment-11347" class="wp-caption-text">Web_API_Config_Class_File</p></div></p>
<p>Then you can add the preceding codes in the static function <em>Register</em>.</p>
<p>[csharp]<br />
var cors = new EnableCorsAttribute(&#8220;*&#8221;, &#8220;*&#8221;, &#8220;*&#8221;);<br />
config.EnableCors(cors);<br />
[/csharp]</p>
<p>IF you do this, the CORS will be applied globally for all the Web API controller you have. This is the easiest way of doing it. Now if you want to see the metadata of <em>EnableCorsAttribute</em>, you can see find it below.</p>
<p>[csharp]<br />
// Summary:<br />
// Initializes a new instance of the System.Web.Http.Cors.EnableCorsAttribute class.<br />
//<br />
// Parameters:<br />
// origins:<br />
// Comma-separated list of origins that are allowed to access the resource. Use<br />
// &#8220;*&#8221; to allow all.<br />
//<br />
// headers:<br />
// Comma-separated list of headers that are supported by the resource. Use &#8220;*&#8221; to<br />
// allow all. Use null or empty string to allow none.<br />
//<br />
// methods:<br />
// Comma-separated list of methods that are supported by the resource. Use &#8220;*&#8221; to<br />
// allow all. Use null or empty string to allow none.<br />
public EnableCorsAttribute(string origins, string headers, string methods);<br />
[/csharp]</p>
<p>As it is mentioned, it accepts the parameters origins, headers, methods. Here we pass * to all the three parameters to make everything to be allowable.</p>
<p>You can also try the same as below in the Register function. Here we are going to apply CORS for particular controller, which means it will be applied for all the actions in the controller. Before that make sure you have added the preceding code in your WebApiConfig.cs file</p>
<p>[csharp]<br />
config.EnableCors();<br />
[/csharp]</p>
<p>And in the API controller you need to set the origins,headers,methods as preceding.</p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.IO;<br />
using System.Linq;<br />
using System.Net;<br />
using System.Net.Http;<br />
using System.Web.Http;<br />
using Newtonsoft.Json;<br />
using Newtonsoft.Json.Converters;<br />
using System.Configuration;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Runtime.Serialization;<br />
using System.Text;<br />
using System.Web;<br />
using System.Web.Http.Cors;</p>
<p>namespace APIServiceApplication.Controllers<br />
{</p>
<p>[EnableCors(origins: &#8220;*&#8221;, headers: &#8220;*&#8221;, methods: &#8220;*&#8221;)]<br />
public class DefaultController : ApiController<br />
{<br />
}<br />
}</p>
<p>[/csharp]</p>
<p>Make sure that you have added namespace <em>using System.Web.Http.Cors;</em> to use CORS. You can always disable CORS in an action by using <em>[DisableCors]</em>.</p>
<p>[csharp]<br />
namespace APIServiceApplication.Controllers<br />
{</p>
<p>[EnableCors(origins: &#8220;*&#8221;, headers: &#8220;*&#8221;, methods: &#8220;*&#8221;)]<br />
public class DefaultController : ApiController<br />
{<br />
[DisableCors]<br />
public string XMLData(string id)<br />
{<br />
return &#8220;Your requested product&#8221; + id;<br />
}<br />
}<br />
}<br />
[/csharp]</p>
<p>Here we have disabled CORS for the action <em>XMLData</em>. And again if you need to apply CORS only in a single action, you can do that as follows.</p>
<p>[csharp]<br />
namespace APIServiceApplication.Controllers<br />
{<br />
public class DefaultController : ApiController<br />
{<br />
[EnableCors(origins: &#8220;*&#8221;, headers: &#8220;*&#8221;, methods: &#8220;*&#8221;)]<br />
public string XMLData(string id)<br />
{<br />
return &#8220;Your requested product&#8221; + id;<br />
}<br />
}<br />
}<br />
[/csharp]</p>
<p>I hope you are aware of how to enable CORS now.</p>
<h3><strong>By adding header informations in Web.config</strong></h3>
<p>Another fix we can do is that add some tags in our Web.config file.</p>
<p>[html]<br />
&lt;system.webServer&gt;<br />
&lt;httpProtocol&gt;<br />
&lt;customHeaders&gt;<br />
&lt;add name=&#8221;Access-Control-Allow-Origin&#8221; value=&#8221;*&#8221; /&gt;<br />
&lt;add name=&#8221;Access-Control-Allow-Headers&#8221; value=&#8221;Content-Type&#8221; /&gt;<br />
&lt;add name=&#8221;Access-Control-Allow-Methods&#8221; value=&#8221;GET,POST,PUT,DELETE,OPTIONS&#8221; /&gt;<br />
&lt;add name=&#8221;Access-Control-Allow-Credentials&#8221; value=&#8221;true&#8221; /&gt;<br />
&lt;/customHeaders&gt;<br />
&lt;/httpProtocol&gt;<br />
&lt;/system.webServer&gt;<br />
[/html]</p>
<p>As you can see we have added keys with value for the listed items.</p>
<ul>
<li>Access-Control-Allow-Origin (For Origin)</li>
<li>Access-Control-Allow-Headers (For Headers)</li>
<li>Access-Control-Allow-Methods (For Methods)</li>
</ul>
<p>Now if you go to your server and check, you can see that all the things are configured perfectly. I have configured my API in my server IIS, so I am going to see my Response Header settings in IIS.</p>
<p>Go to the command window and type &#8220;inetmgr&#8221; and click OK, your IIS wilbe openeded shortly, now find your Web API which you have already configured under Default Web Site. Before doing this, please make sure that you have configured IIS in your windows. If you don&#8217;t know how to configure, I strongly recommend you to read <a href="http://sibeeshpassion.com/configure-iis-in-windows/" target="_blank" rel="noopener">Configure IIS in Windows </a>.</p>
<p><div id="attachment_11348" style="width: 248px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/Configured_Web_API_in_IIS.png"><img decoding="async" aria-describedby="caption-attachment-11348" class="size-full wp-image-11348" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/Configured_Web_API_in_IIS.png" alt="Configured_Web_API_in_IIS" width="238" height="92" /></a><p id="caption-attachment-11348" class="wp-caption-text">Configured_Web_API_in_IIS</p></div></p>
<p>Go to Features View and double click on HTTP Response Headers under IIS category.</p>
<p><div id="attachment_11349" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/HTTP_Response_Headers_In_IIS-e1457687018859.png"><img decoding="async" aria-describedby="caption-attachment-11349" class="size-full wp-image-11349" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/HTTP_Response_Headers_In_IIS-e1457687018859.png" alt="HTTP_Response_Headers_In_IIS" width="650" height="455" srcset="/wp-content/uploads/2016/03/HTTP_Response_Headers_In_IIS-e1457687018859.png 650w, /wp-content/uploads/2016/03/HTTP_Response_Headers_In_IIS-e1457687018859-300x210.png 300w, /wp-content/uploads/2016/03/HTTP_Response_Headers_In_IIS-e1457687018859-400x280.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11349" class="wp-caption-text">HTTP_Response_Headers_In_IIS</p></div></p>
<p>You can see all the settings has been configured there.</p>
<p><div id="attachment_11350" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/03/HTTP_Response_Headers_Available-e1457687318857.png"><img decoding="async" aria-describedby="caption-attachment-11350" class="size-full wp-image-11350" src="http://sibeeshpassion.com/wp-content/uploads/2016/03/HTTP_Response_Headers_Available-e1457687318857.png" alt="HTTP_Response_Headers_Available" width="650" height="456" srcset="/wp-content/uploads/2016/03/HTTP_Response_Headers_Available-e1457687318857.png 650w, /wp-content/uploads/2016/03/HTTP_Response_Headers_Available-e1457687318857-300x210.png 300w, /wp-content/uploads/2016/03/HTTP_Response_Headers_Available-e1457687318857-400x281.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11350" class="wp-caption-text">HTTP_Response_Headers_Available</p></div></p>
<h3>CORS in Asp.Net Core application</h3>
<p>Though the mechanism is the same, the way you do things in Asp.Net core application. To set the CORS in asp.net application, you should add the preceding code in your ConfigureServices method in Startup.cs file before the <em><span class="n">services</span><span class="p">.</span><span class="nf">AddMvc</span><span class="p">(); </span></em><span class="p">call</span>.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">services.AddCors(cors =&gt; cors.AddPolicy("CorsPolicy", builder =&gt; {
 builder.AllowAnyHeader()
  .AllowAnyMethod()
  .AllowAnyOrigin();
}));</pre>
<p>You should also use this policy you have created in the Configure method in Startup.cs before the <em><span class="n">app</span><span class="p">.</span><span class="nf">UseMvc</span><span class="p">(); </span></em><span class="p">call.</span></p>
<pre class="EnlighterJSRAW" data-enlighter-language="csharp">app.UseCors("CorsPolicy");</pre>
<p>That&#8217;s all, now if you run your application, you will be able to fetch the data from your Web API.</p>
<h2><strong>Conclusion</strong></h2>
<p>Did I miss anything that you may think which is needed? Have you ever faced this issue? Did you try Web API yet? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><strong>Your turn. What do you think?</strong></h2>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I am able to.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/fix-to-no-access-control-allow-origin-header-is-present-or-working-with-cross-origin-request-in-asp-net-web-api/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
	</channel>
</rss>
