# CORS設定

### 概観

いわゆるクロスオリジンエラーと呼ばれる以下のようなエラーが発生した場合は、いわゆる同一生成元ポリシーに違反しています。

{% hint style="warning" %}
XMLHttpRequestは<http://remote-domain/urlを読み込めません。\\>
リクエストされたリソースに「Access-Control- Allow-Origin」ヘッダーがありません。\
Origin '<http://localdomain.com> 'はアクセスを許可されません。
{% endhint %}

同一生成元ポリシーはCORS（クロスオリジンリソースシェアリング）を許可しません。 したがって、HTML5ビューアーがインストールされていないサーバーからHTML5ビューアーを呼び出すには、そのサーバーでCORS設定が必要です。(参照：[https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS）。))

![](https://gblobscdn.gitbook.com/assets%2F-M0LRvAG2w89F7pN5LX0%2F-M0REf6MJQCrAgEYcDy8%2F-M0RFi9ZQRY84I4peEVR%2Ftech-html5-cors.png?alt=media\&token=eba2f2a3-7ebd-4464-93ec-1a60636fe07b)

### JAVAのCORS設定

#### TomcatのCORS設定(cors-filter)

1. **cors-filter-1.8.jar**および**java-property-utils-1.9.jar**を以下からダウンロードします。<http://discventionstech.wordpress.com/2014/01/19/resolve-tomcat-7-cors-error/> <http://software.dzhuvinov.com/cors-filter-installation.html>
2. 2つのファイルをtomcat / libにコピーします。
3. tomcat / conf / web.xmlを開き、すべてのcors設定をコメント化します。
4. 以下の行をコピーして貼り付けます。
5. Tomcatを再起動します。

```markup
<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-cla
</filter>
<filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
```

### .NETのCORS設定

#### IISのCORS設定(cors-filter)

1. ozサーバーのインストールでweb.configを開きます。&#x20;
2. 以下の行をコピーして貼り付けます。&#x20;
3. IISを再起動します。

```markup
<system.webServer>
    <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="POST, GET" />
        <add name="Access-Control-Allow-Headers" value="Origin, X-Requested" />
    </customHeaders>
  </httpProtocol>
</system.webServer>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jp.ozeform.io/guide/html5-viewer/cors-settings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
