Solucionar Cors en Aplicaciones Genexus C#
Solucionar Manual
Modificar el web.config de la aplicación.
Buscar el Nodo
<system.webServer>dentro del XML.Copiar dento de
<system.webServer>el siguiente código.
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type,Authorization" />
</customHeaders>
</httpProtocol>
- Dentro de
<system.webServer> <rewrite>copiar dentro de<rules>las siguientes reglas
<rule name="CORS Preflight Rest Services" stopProcessing="true">
<match url="^rest/((?:/?[\w \.-]+)+)/?(.*)$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^OPTIONS$" />
</conditions>
<action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflight" />
</rule>
<rule name="CORS Preflight Anonymous Authentication" stopProcessing="true">
<match url="^oauth/access_token$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^OPTIONS$" />
</conditions>
<action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflight" />
</rule>

Solución Automática
Esta opción puede ser usada en CI/CD porque es un script PowerShell. Modificar la primera y ultima linea con la dirección del fichero a modificar.
$xml = [xml](Get-Content C:\inetpub\wwwroot\ICDigitalSport\web.config)
$node = $xml.SelectSingleNode("//httpRuntime")
$node.SetAttribute("maxRequestLength","100048576")
$node.SetAttribute("executionTimeout","3600")
$webserver = $xml.SelectSingleNode("//system.webServer")
$httpProtocol = $xml.CreateElement("httpProtocol")
$httpProtocol.InnerXml= '<customHeaders><add name="Access-Control-Allow-Origin" value="*" /><add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" /><add name="Access-Control-Allow-Headers" value="Content-Type,Authorization" /></customHeaders>'
$httpProtocol = $webserver.AppendChild($httpProtocol)
$rules = $xml.SelectSingleNode("//rules")
$rule1 = $xml.CreateElement("rule")
$rule1.SetAttribute("name","CORS Preflight Anonymous Authentication")
$rule1.SetAttribute("stopProcessing","true")
$rule1.InnerXml = '<match url="^oauth/access_token$" /><conditions><add input="{REQUEST_METHOD}" pattern="^OPTIONS$" /></conditions><action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflight" />'
$rules.InsertBefore($rule1, $rules.FirstChild)
$rule2 = $xml.CreateElement("rule")
$rule2.SetAttribute("name","CORS Preflight Rest Services")
$rule2.SetAttribute("stopProcessing","true")
$rule2.InnerXml = '<match url="^rest/((?:/?[\w \.-]+)+)/?(.*)$" /><conditions><add input="{REQUEST_METHOD}" pattern="^OPTIONS$" /></conditions><action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflight" />'
$rules.InsertBefore($rule2, $rules.FirstChild)
$xml.Save("C:\inetpub\wwwroot\ICDigitalSport\web.config")