【问题标题】:ImageProcessor / Windows Azure Storage issue, returns 403 ForbiddenImageProcessor / Windows Azure 存储问题,返回 403 Forbidden
【发布时间】:2017-02-14 03:25:38
【问题描述】:

这些图像可以加载到本地 ENV 中,也可以加载到生产环境中。但是,暂存环境根本无缘无故无法加载这些。

<package id="ImageProcessor" version="2.2.0.0" targetFramework="net45" />
  <package id="ImageProcessor.Web" version="4.2.1.0" targetFramework="net45" />
  <package id="ImageProcessor.Web.Config" version="2.2.0.0" targetFramework="net45" />
  <package id="ImageProcessor.Web.Plugins.AzureBlobCache" version="1.0.0.0" targetFramework="net45" />
  <package id="ImageProcessor.Web.PostProcessor" version="1.0.2.0" targetFramework="net45" />
  <package id="UmbracoAzureBlobStorageProvider" version="1.0.10.5" targetFramework="net45" />
  <package id="WindowsAzure.Storage" version="4.3.0" targetFramework="net45" />

我正在使用 ImageProcessor,并且域已根据需要列入白名单:

<whitelist>
        <add url="http://conceptjp.blob.core.windows.net/"/>
        <add url="https://az739977.vo.msecnd.net/"/>
</whitelist>

https://staging.conceptjp.com/remote.axd?https://az739977.vo.msecnd.net/media/6883/logo-sparitual.png?quality=70(不工作)

https://conceptjp.com/remote.axd?https://az739977.vo.msecnd.net/media/6883/logo-sparitual.png?quality=70(有效)

https://cjp.local/remote.axd?https://az739977.vo.msecnd.net/media/6883/logo-sparitual.png?quality=70(工作,本地环境)

2016-10-04 13:31:11.2393 Logging.TheLogger The remote server returned an error: (403) Forbidden. The remote server returned an error: (403) Forbidden.    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
   at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ImageProcessor.Web.Plugins.AzureBlobCache.AzureBlobCache.<IsNewOrUpdatedAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ImageProcessor.Web.HttpModules.ImageProcessingModule.<ProcessImageAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
   at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)

【问题讨论】:

标签: asp.net-mvc umbraco azure-storage imageprocessor


【解决方案1】:

我不知道在这里说什么。几乎所有东西都以我不期望也不推荐的方式使用。

如果您在 Azure 上使用 Umbraco,您应该为您的媒体使用以下插件。

https://github.com/JimBobSquarePants/UmbracoFileSystemProviders.Azure

您使用的FileSystemProvider 已经过时了大约一年半。它实际上建议在其主页中使用上面提到的插件。

新包 UmbracoFileSystemProviders.Azure 上线! 见:https://our.umbraco.org/projects/collaboration/umbracofilesystemprovidersazure/

我推荐它而不是这个,特别是如果您使用的是 Umbraco 7.3 或更高版本。它解决了您在后台会遇到的许多问题。

https://our.umbraco.org/projects/backoffice-extensions/azure-blob-storage-provider

原因是原始提供程序存在缺陷,如果不完全重写就无法修复。

  1. 媒体使用绝对 url 存储在数据库中。这意味着不能在多个环境中使用相同的媒体。
  2. 媒体已下载并在后台显示未处理。这导致不必要地下载了 100s MB 的数据,从而破坏了大型网站的性能。

在开始使用数据库之前,您必须替换您的媒体引用,以从存储的 url 中删除域。我个人建议从头开始重建您的媒体部分。

GitHub 页面上有全面的说明,但我也会在下面列出。

首先。卸载旧插件,将所有 ImageProcessor 库更新到最新版本并安装推荐的 FileSystemProvider 插件

然后更新~/Config/FileSystemProviders.config,将默认提供程序替换为以下内容:

<?xml version="1.0"?>
<FileSystemProviders>
  <Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure">
    <Parameters>
      <add key="containerName" value="media" />
      <add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" />
      <add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]"/>
      <!--
        Optional configuration value determining the maximum number of days to cache items in the browser.
        Defaults to 365 days.
      -->
      <add key="maxDays" value="365" />
    </Parameters>
  </Provider>
</FileSystemProviders>

您现在需要配置 CloudImageService 以捕获所有以 /media/ 开头的请求

<?xml version="1.0"?>
<security>
  <services>
    <service name="LocalFileImageService" type="ImageProcessor.Web.Services.LocalFileImageService, ImageProcessor.Web"/>
    <service prefix="media/" name="CloudImageService" type="ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web">
      <settings>
        <setting key="Container" value="media"/>
        <setting key="MaxBytes" value="8194304"/>
        <setting key="Timeout" value="30000"/>
        <setting key="Host" value="http://[myAccountName].blob.core.windows.net/media"/>
      </settings>
    </service>
  </services>  

确保您的缓存配置设置正确。

<caching currentCache="AzureBlobCache">
  <caches>
    <!-- Disk cache configuration removed for brevity -->
    <cache name="AzureBlobCache" type="ImageProcessor.Web.Plugins.AzureBlobCache.AzureBlobCache, ImageProcessor.Web.Plugins.AzureBlobCache" maxDays="365">
      <settings>
        <!-- The Account, Container and CDN details -->
        <setting key="CachedStorageAccount" value="DefaultEndpointsProtocol=https;AccountName=[CacheAccountName];AccountKey=[CacheAccountKey]"/>
        <setting key="CachedBlobContainer" value="cache"/>
        <!-- Whether to add the container name to the CDN url. Newer Azure formats require false. -->
        <setting key="UseCachedContainerInUrl" value="true"/>
        <!-- Full CDN root url e.g http://123456.vo.msecnd.net/ -->
        <setting key="CachedCDNRoot" value="[CdnRootUrl]"/>
        <!-- Optional setting for a timeout limit in milliseconds when attempting to communicate with the CDN url. -->
        <setting key="CachedCDNTimeout" value="1000"/>
        <!-- 
            Optional settings for better identifcation of source images if stored in 
            Azure blob storage.
         -->
        <setting key="SourceStorageAccount" value=""/>
        <setting key="SourceBlobContainer" value=""/>
        <!-- 
            Optional settings facilitate streaming of the blob resource directly instead of a redirect. This is beneficial
            for CDN purposes but caution should be taken if not used with a CDN as it will add quite a bit of overhead 
            to the site. 
         -->
        <setting key="StreamCachedImage" value="false"/>
      </settings>
    </cache>
  </caches>
</caching>

现在应该使用根相对路径 /media/ 创建图像请求,仅内置虚拟路径提供程序将拦截并相应地处理。

例如/media/1046/car-small.jpg?width=500&amp;height=500&amp;mode=boxpad&amp;bgcolor=hotpink

【讨论】:

  • 你认为 [conceptjp.com] 图像消失只是时间问题吗?
  • 恐怕我不明白你在问什么。
  • @JamesSouth - 我猜他是在问他是否可以跳过你提供给他的修复的后半部分,然后等待人们更新足够多的图像以使数据库中没有绝对 URL。听起来这里有很多弯路:\
  • @JamesSouth 解决方案是将服务器上的时钟设置为 UTC。 stackoverflow.com/questions/22828279/…
  • @GabrielRobert 但事实并非如此。我已经详细解释了您没有正确使用该软件的原因。没有必要问你是否不听。
猜你喜欢
  • 2014-06-15
  • 1970-01-01
  • 2013-07-23
  • 2018-08-13
  • 1970-01-01
  • 2012-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多