【发布时间】:2015-07-02 18:54:21
【问题描述】:
我知道Same-Origin policy 提供引用另一台服务器上内容的内容的问题。然而,我找到了CORS (Cross-Origin Resource Sharing),并希望它能做我想做的事。我还没有运气,主要是因为我不完全理解它。我也很难找到 CORS 和 XML/XSLT 的示例。
这是我所做的:
1.在我的 web.config 中添加了以下内容
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
2。创建了以下名为hello.xml 的 XML 文件并将其上传到 scott.host/
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://scott.host/hello.xsl"?>
<hello-world> <greeter>An XSLT Programmer</greeter> <greeting>Hello, World!</greeting></hello-world>
3.创建了以下名为 hello.xsl 的 XSL 文件并将其上传到另一个域(同一服务器)
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/hello-world">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<H1>
<xsl:value-of select="greeting"/>
</H1>
<xsl:apply-templates select="greeter"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
当我访问http://scott.host/hello.xml 时,它会按预期正确显示转换。但是,当我访问 http://otherdomain/hello.xml 时,我得到了 Request for cross-domain XSLT was denied 错误。
我是不是做错了什么?
注意:发布此内容后,我已在我的 webconfig 中禁用了 Access-Control-Allow-Origin 条目。
参考资料:
【问题讨论】:
-
对不起,引用中的嵌套代码,它根本没有显示出来,只是一个代码块。
-
删除了引用块,现在可以正常显示了。
-
@Dijkgraaf 很奇怪,谢谢。
标签: xml xslt cors same-origin-policy