2012-01-02 28 views
0

我在中繼器內部有一個圖像控件。我想排除/忽略imageurl屬性中的參數,因爲路徑(源圖像)在名稱中沒有此參數,但我仍然想在url中顯示參數。我不能重新命名所有的圖像,因爲有很多。希望它是有道理的。排除/忽略圖像ImageUrl中的參數,但仍顯示在Repeater內

這裏是一個例子。

這是SEO。原路徑

  • /product/0001_100_00_KK00_F02.png

我理想中IMAGEURL顯示

  • /product/0001_100_00_KK00_F02.png/Tv-Sony-lcd-black-bravia- KDL-26V4500

OR

  • /product/0001_100_00_KK00_F02/Tv-Sony-lcd-black-bravia-KDL-26V4500.png
<asp:Repeater ID="rptImages" runat="server"> 
     <ItemTemplate> 
      <asp:Image ID="Image1" ImageUrl='<%# Eval("Url") %>' runat="server" /> 
     </ItemTemplate> 
    </asp:Repeater> 

而且代碼隱藏

rptImages.DataSource = Images.Select(s => new { Url = s }); 
    rptImages.DataBind(); 

這適用於原始路徑。但是當我添加/Tv-Sony-lcd-black-bravia-KDL-26V45000到URL的結尾時,圖像沒有找到(當然)。

那麼如何添加一個額外的參數到imageurl,但讓圖像控制忽略這一點,仍然找到圖像路徑?

任何人都不會有如何解決這個問題

+1

圖像控件沒有_find_圖像,它只是輸出你請求的URL。是否可以找到圖像是您的網絡服務器如何響應客戶端瀏覽器提出的圖像URL請求的問題。 – 2012-01-02 13:04:41

回答

0

您可以通過URL重寫實現該功能。將global.asax文件添加到您的項目並使用某種重寫邏輯。

void Application_BeginRequest(Object sender, EventArgs e) 
{ 
    string currentPath; 
    currentPath = Request.Path; // /product/0001_100_00_KK00_F02.png/Tv-Sony-lcd-black-bravia-KDL-26V4500 
    if (currentPath.IndexOf(".png") > -1) 
    { 
     string[] paths = currentPath.Split('/'); 
     currentPath = currentPath.Replace("/" + paths[paths.Length - 1], ""); // /product/0001_100_00_KK00_F02.png 
     Context.RewritePath(currentPath); 
    } 
} 

這會工作,但也將重寫其中包含「巴紐」,因爲‘如果(currentPath.IndexOf(’PNG‘)> -1)’ 它是安全的,包括一些所有request.paths更多的空調。

+0

謝謝你們的快速回復。 :) 這兩個解決方案似乎工作到目前爲止我的目的很好。 現在處於測試模式.. – Future 2012-01-02 14:08:25

0

任何想法,將這樣的工作網址?

/product/0001_100_00_KK00_F02.png?Tv-Sony-lcd-black-bravia-KDL-26V4500

只要你把一個問號的文件名後,你的圖像將顯示就好了。正如@Jon Edgerton指出的那樣,IIS沒有找到您的映像,這就是爲什麼它不顯示。

如果你想要一個完全自定義的URL,那麼你將不得不做一些URL重寫。這裏有一篇文章:http://learn.iis.net/page.aspx/517/url-rewriting-for-aspnet-web-forms/

+0

謝謝你們的快速回復。 :) 這兩個解決方案似乎工作到目前爲止我的目的很好。 現在處於測試模式.. – Future 2012-01-02 14:08:19

+0

請確保您接受答案並投票回答有用的答案。 – Brian 2012-01-02 20:24:45

相關問題