2010-04-13 27 views
6

我剛剛升級到.NET 4,並且我的ASP.NET圖表控件不再顯示。ASP.NET Charting Control不再使用.NET 4

對於.NET 3.5,由控制產生的HTML用於看起來像這樣:

<img id="20_Chart" src="/ChartImg.axd?i=chart_5f6a8fd179a246a5a0f4f44fcd7d5e03_0.png&amp;g=16eb7881335e47dcba16fdfd8339ba1a" alt="" style="height:300px;width:300px;border-width:0px;" /> 

,現在,對於.NET 4,它看起來像這樣(注意在源路徑的變化):

<img id="20_Chart" src="/Statistics/Summary/ChartImg.axd?i=chart_5f6a8fd179a246a5a0f4f44fcd7d5e03_0.png&amp;g=16eb7881335e47dcba16fdfd8339ba1a" alt="" style="height:300px;width:300px;border-width:0px;" /> 

圖表是在是在所謂的「統計」和MVC視圖的MVC區文件夾中的MVC局部視圖文件夾中稱爲「摘要」(即,「/地區/統計/查看/摘要」),所以這顯然是路徑變化的來源。

我所做的只是將System.Web.DataVisualization程序集從3.5切換到4.0。

任何幫助非常感謝。

回答

1

謝謝您的回答,但我不認爲我是一個IIS6/IIS7問題。

我將其追溯到ChartControl上的ImageStorageMode的默認值已從UseImageLocation更改爲UseHttpHandler。我的ChartControl現在有一些額外的屬性,所有工作正常。

<asp:Chart ... ImageStorageMode="UseImageLocation" ImageLocation="/Temp/ChartPic_#SEQ(300,3)"> 

我不得不也改變ImageLocation是非相對的(通過添加/Temp/),其還遍歷在一些代碼隱藏ChartControlDataPoints時引起的問題。

7

從ASP.NET 3.5升級到使用ASP.NET MVC的ASP.NET 4.0後,我們在IIS 6上遇到了同樣的問題。在IIS 7上一切正常,但IIS 6給了我們一個問題。

的問題是,所述HttpContext.Current.Request.CurrentExecutionFilePath屬性在IIS 6和IIS 7,得到了不同的結果:

  • 地址:/Controller.mvc/Action/1/2
  • IIS 6:/Controller.mvc/Action/1/2
  • IIS 7: /Controller.mvc

這就造成了網址,如圖表:

  • IIS 6:/Controller.mvc/Action/1/ChartImg.axd?i=chart_...
  • IIS 7:/ChartImg.axd?i=chart_...

的ChartHttpHandler得到了一個函數在那裏,基於關計算路徑的HttpContext.Current.Request.CurrentExecutionFilePath:

private static string GetHandlerUrl() 
{ 
    string str = Path.GetDirectoryName(HttpContext.Current.Request.CurrentExecutionFilePath ?? "").Replace(@"\", "/"); 
    if (!str.EndsWith("/", StringComparison.Ordinal)) 
    { 
     str = str + "/"; 
    } 
    return (str + "ChartImg.axd?"); 
} 

ASP.NET UrlRewriting工作的方式,因爲ChartImg.axd的路徑仍然具有.mvc,所以MVC處理程序正在被調用而不是Chart處理程序。

有3種方式,我們找到對付它(詳見下文):

  1. 爲「.mvc」添加一個明確的腳本映射到ASP.NET 4.0的dll
  2. 添加一些額外的忽略路由到路由表中,以覆蓋排列
  3. 重寫執行()控制器,並把在重定向回/ChartImg.axd

(1)原來,如果我們通過IIS 6.0爲.mvc添加了.mvc的腳本映射請求。CurrentExecutionFilePath會得到計算爲根路徑,我們怎麼想的,而不是爲更深的路徑

  • IIS 6.0經理
  • 屬性是 - >主目錄 - >配置
  • 映射選項卡
  • 可執行文件:C: \ WINNT \ microsoft.net \框架\ v4.0.30319 \ ASPNET_ISAPI.DLL,擴展:.mvc

(2)我們發現,廣告但我們必須考慮路徑中所有可能的深度,以便讓ASP.NET MVC忽略ChartImg.axd(如果它深深嵌入在路徑中而不是根目錄):


(3)通過重寫通過製備基礎控制器,我們所有的控制器繼承的execute()我們所有的控制器,我們可以在全球覆蓋的execute()考慮到這一情況,並重定向到/ ChartImg。 axd

public partial class MyController: Controller 
    { 
     protected override void Execute(RequestContext cc) 
     { 
      // the url for chartimg.axd to be in the application root. /Controller.mvc/Action/Param1/ChartImg.axd gets here first, 
      // but we want it to go to /ChartImg.axd, in which case the IgnoreRoute does work and the chart http handler does it's thing. 
      if (cc.HttpContext.Request.Url.AbsoluteUri.Contains("ChartImg.axd")) 
      { 
       var url = new UriBuilder(cc.HttpContext.Request.Url); 
       url.Path = "/ChartImg.axd"; 
       cc.HttpContext.Response.Redirect(url.ToString()); 
       return; 
      } 
     } 
    } 
+1

額外的RouteTable.Routes.IgnoreRoute爲我們做了訣竅。 – badMonkey 2014-03-27 15:06:34

18

雖然@邁克爾的解決方案提供了爲什麼th問題存在,有一個更簡單的解決方案。當註冊在控制器路由中的global.asax.cs處理,你可以添加一個contstraint忽略的路徑,如下:

protected void Application_Start() { 
    ... 
    RouteTable.Routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" }); 
    ... 
} 
+1

Michael Ferrante的回答非常好 - 但我無法對此解決方案進行足夠的投票...... cheers Kevin – 2010-09-28 14:15:45