XMLHttpRequest cannot load http://192.168.0.100:30755/api/values. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.101:8018' is therefore not allowed access.
aurelia 部署在
http://192.168.0.101:8018
數據來源地址
http://192.168.0.100:30755
aurelia 請求訪問100:30755上面的數據就會有跨域問題也就是剛上面的錯誤
解決辦法:
在0.100:30755上面設置
<pre class="lang-cs prettyprint prettyprinted" style="margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-size: 13px; overflow: auto; width: auto; max-height: 600px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; color: rgb(57, 51, 24); word-wrap: normal; background-color: rgb(238, 238, 238);"><code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><span class="str" style="margin: 0px; padding: 0px; border: 0px; color: rgb(128, 0, 0);">Access-Control-Allow-Origin: *</span></code>
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS
設置方式有多種
web.config或者代碼設置也行。