Solucionar problema CORS en servicios asmx

Agregar en web.config lo siguiente:

<configuration>
       ....
       ....
       ....

<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://servidor-origen-habilitado"/>
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
</customHeaders>
</httpProtocol>
</system.webServer>

</configuration>

Ej, si se quiere admitir que desde http://Xdesa:8080 se pueda llegar al servicio 'http://Xdesa/wsX/Seguridad.asmx/ExisteRolUsuario, poner lo siguiente:

<add name="Access-Control-Allow-Origin" value="http://Xdesa:8080"/>



(el error que da si no se agregan estas lineas es:
Access to XMLHttpRequest at ... from origin ... has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource)

No hay comentarios:

Publicar un comentario