[IIS] Khắc phục lỗi CORs missing allow origin IIS

Cross Origin Resource Sharing là một tiêu chuẩn của W3C cho phép một user agent gửi request

1. Các bạn cài đặt iis-cors-module cho IIS tại link https://www.iis.net/downloads/microsoft/iis-cors-module

2. Khai báo trong web.config với mẫu sau, các bạn tùy biến lại nhé

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <cors enabled="true" failUnlistedOrigins="true">
            <add origin="*" />
            <add origin="https://*.microsoft.com"
                 allowCredentials="true"
                 maxAge="120">
                <allowHeaders allowAllRequestedHeaders="true">
                    <add header="header1" />
                    <add header="header2" />
                </allowHeaders>
                <allowMethods>
                     <add method="DELETE" />
                </allowMethods>
                <exposeHeaders>
                    <add header="header1" />
                    <add header="header2" />
                </exposeHeaders>
            </add>
            <add origin="http://*" allowed="false" />
        </cors>
    </system.webServer>
</configuration>

Chúc các bạn thành công

Bình luận