2017-03-06 18 views
1

我正在使用WebViewer 2.2.2并尝试在ASP.NET MVC 5视图中显示存储在Azure Blob存储中的XOD文件,网址为: https://somename.blob.core.windows.net/containername/GettingsStarted.xodPDFTron WebViewer - 尝试显示存储在Azure BLOB存储中的XOD文件时出现CORS错误

我得到了浏览器控制台CORS错误为“CORS未启用,或者发现这一要求的任何匹配规则。

我发现URL https://www.pdftron.com/webviewer/demo/tutorials/xdomain.html启用CORS。我应该在proxy.html文件中提供哪个URL,因为存储在Azure BLOB存储中的每个XOD blob都会有一个不同的URL。

部分https://somename.blob.core.windows.net/containername/会相同,但是对于不同的XOD,文件名会有所不同。那么,我如何在proxy.html文件中传递XOD文件名?

这是处理CORS问题的正确方法https://www.pdftron.com/webviewer/demo/tutorials/xdomain.html还是有另一种更简单的方法?

@model XODViewer.DataModel.Document 

    @{ 
     ViewBag.Title = "Document"; 
    } 

    @Scripts.Render("~/bundles/jquery") 
    <script src="~/lib/WebViewer.min.js"></script> 

    <style> 
     #viewer { 
      width: 1024px; 
      height: 600px; 
     } 
    </style> 

    <script> 
     $(function() { 
       var viewerElement = document.getElementById('viewer'); 
       var myWebViewer = new PDFTron.WebViewer({ 
        path: 'lib', 
        type: 'html5', 
        documentType: "xod", 
initialDoc:"https://somename.blob.core.windows.net/containername/GettingsStarted.xod", 
        config: '../../lib/WebViewerConfig.js', 
        streaming: true, 
        enableAnnotations: false, 
        enableOfflineMode: false, 
        enableReadOnlyMode: true, 
        azureWorkaround: true 
       }, viewerElement); 
      }); 
    </script> 

    <div id="viewer"class="xod-viewer-div"> 
    </div> 

回答

1

根据你的描述,我跟着这个tutorial开始使用WebViewer。我可能会遇到同样的错误,正如你所说如下:

<script> 
    $(function() { 
     var viewerElement = document.getElementById("viewer"); 
     var myWebViewer = new PDFTron.WebViewer({ 
      path: "/libs", 
      type: "html5", 
      documentType:'xod', 
      initialDoc:"https://brucechen.blob.core.windows.net/docs/GettingStarted.xod" 
     }, viewerElement); 
    }); 
</script> 

enter image description here

对于跨域访问,你可以利用Microsoft Azure Storage Explorer配置CORS设置如下:

结果

enter image description here

+0

MaxAgeInSeconds定义中指出“这定义秒浏览器的最大数目将缓存飞行前请求。由于这些“预先飞行”请求是可计费的,因此通常建议您将此值设置为较高的数值,以便浏览器不会频繁发出此“预先飞行”请求。(1)可以将其留给值为100甚至可能更改为50,因为我相信一旦在WebViewer中下载了XOD,就不会再有浏览器发出请求(2)在PROD Azure实例中设置相同设置是否安全(3)任何PowerShell cmdlet例子 –

+1

(1)对于MaxAgeInSeconds,您可以按照您的预期更改为50(2)容器访问级别是只读的,为了更安全的方式,您可以为特定原点添加CORS规则(3)您可以参考到这个[示例](https://gist.github.com/irwinwilliams/4cf93b6e2461c753ff125590650186ae)。 –