2014-02-08 41 views
0

最近,我將ASP.NET WebForms項目升級爲MVC混合。如何在MVC升級後修復chartimg.axd

但是,它打破了我們的ASP.NET圖表控件 - 圖像不再呈現在報表中。

從圖表控件的3.5升級到4.0也可能是問題所在。我將本地複製的3.5程序集的引用替換爲4.0 GAC版本的System.Web.UI.DataVisualization.Charting程序集。

回答

1

有幾個步驟來得到這個工作再次

1)下面是在web.config

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.web> 
     <pages> 
     <controls> 
      <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     </controls> 
     </pages> 
     <compilation defaultLanguage="c#" targetFramework="4.5"> 
     <assemblies> 
      <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     </assemblies> 
     </compilation> 
    </system.web> 
    <system.webServer> 
     <handlers> 
     <remove name="ChartImageHandler" /> 
     <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     </handlers> 
    </system.webServer> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.DataVisualization" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
      <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 

2) 我需要無視AXD的路線的相關片段。請求圖表圖像的URL是形式的http://sitename/reports/chartimg.axd?i=chart444334&i=0

所以我不得不小心包括/報告/ URL在路由

routes.IgnoreRoute("Reports/{resource}.axd/{*pathInfo}"); 

注意,這需要在頂部將的路線。放置在路由配置的底部時它不起作用。 MVC路由中的專家可能是LDO,但對我來說並不明顯。

3)此時圖表正在生成,但我仍然得到404圖像未找到當試圖服務圖表圖像。這意味着我的web.config中可能還存在一個問題。

我放棄了嘗試使用HTTP處理程序並切換到基於文件的位置。這適用於圖表控件本身:

ImageStorageMode = ImageStorageMode.UseImageLocation; 

這不是理想的,如果你不想讓好奇的​​用戶枚舉圖表的編號是可以預見的,幸運的是我的圖表是不夠敏感,值得關注。

這也意味着第一步中的一些web.config可以被刪除。