Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement "Access-Control-Allow-Origin" header in asp.net

Tags:

c#

asp.net

iis

Is it possible to implement "Access-Control-Allow-Origin" header in asp.net

like image 369
Nitin S Avatar asked Jun 29 '11 06:06

Nitin S


People also ask

How add Access-Control allow Origin header in asp net?

First, we need to enable CORS in WebAPI, then we call the service from other application AJAX request. In order to enable CORS, we need to install the JSONP package from NuGet (see Figure3). After adding Jsonp package, we need to add the following code-snippet in App_Start\WebApiConfig. cs file.


2 Answers

From enable-cors.org:

CORS on ASP.NET

If you don't have access to configure IIS, you can still add the header through ASP.NET by adding the following line to your source pages:

Response.AppendHeader("Access-Control-Allow-Origin", "*"); 

See also: Configuring IIS6 / IIS7

like image 180
dtb Avatar answered Oct 06 '22 20:10

dtb


Another option is to add it on the web.config directly:

<system.webServer>     <httpProtocol>       <customHeaders>         <add name="Access-Control-Allow-Origin" value="http://www.yourSite.com" />         <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>         <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />       </customHeaders>     </httpProtocol> 

... I found this in here

like image 26
DanielV Avatar answered Oct 06 '22 20:10

DanielV