2017-06-05 114 views
0

我在.NET Framework 4.5.1中使用了MVC 4。將視圖內的文件夾路徑上下文更改爲根目錄

我正在使用外部庫創建圖表。 HTML引用了一個動態創建的圖像,

<img usemap="#MainContent_C1WebChart1_MAP" id="MainContent_C1WebChart1" src="chartimage.aspx?SessionID=FooBar&amp;Delete=T">

但它看着/Home/chartimage.aspx?SessionID=FooBar&amp;Delete=T(返回未找到文件)

它目前存在的/chartimage.aspx?SessionID=FooBar&amp;Delete=T

下什麼是解決的最好辦法這個路徑錯誤?我不能在運行時將img中的src屬性更改爲包含'/',因爲它是由外部庫生成的。

控制器: /控制器/ HomeController的

查看: /瀏覽/首頁/ SITEMASTER和/Views/Home/Default.aspx。

如果我使這個視圖成爲默認的啓動頁面, RouteConfig:

 routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 
     //localhost:9000 Works great! But I don't want this as the default page. 
     //localhost:9000/Home/Index Doesn't work :(It's trying to get the resource from /Home/chartimage.aspx... 
+0

你可以使用jQuery – ISHIDA

回答

1

使用本link如何改變圖像的src值。

如果你想使用重寫URL:

<rule name="Remove en" stopProcessing="true"> 
    <match url="^(.*)/Home$" /> 
    <action type="Rewrite" url="{R:1}" /> 
</rule> 

如果你的例子www.local.com/home/chartimage.aspx將被改寫爲

www.local.com/chartimage.aspx 
+0

感謝您的聯繫石田的改變src值!我在想那個;這是好的做法嗎?或者重新映射服務器端的路由是更好的選擇 – WCGPR0

+0

我會說使用jquery處理它,而不是通過路由處理它。其他方法是在web.config文件中編寫重寫規則。 – ISHIDA

+0

您是否也可以在重定向/ Home/*至/ *的重寫規則的回答中提供示例(RouteConfig中定義的現有路由除外)? – WCGPR0