1. 程式人生 > >arcgis js api呼叫SOE 設定代理後 呼叫報No 'Access-Control-Allow-Origin' header is present on the requested ...

arcgis js api呼叫SOE 設定代理後 呼叫報No 'Access-Control-Allow-Origin' header is present on the requested ...

使用ArcGIS API for JavaScript 呼叫SOE,在設定了代理之後進行請求 報“No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.”錯誤

經對網上搜索到的各種解決方法進行測試,下面的方法能夠解決上面的問題:即在web.config中的<system.webServer>標記中新增下面的內容

<httpProtocol>
    <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    </customHeaders>
</httpProtocol>
<handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."   verb="*" 
         type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>