2009-11-20 72 views
1

這真的很奇怪。我的網站圖像顯示不正確。如果在網址末尾添加斜線,則會顯示,否則它們不顯示。請看:根據URL不顯示圖像:最後加上或不加破折號「/」

這到底是用破折號鏈接: http://jobbox.com.br/cocoonhealth/insurance/private-health-insurance/

要看到問題,刪除破折號到底...。圖像將不再顯示了。

有趣的是,當我看着html代碼,是完全一樣的。我有一些特定的路線,但這個問題遍佈整個網站。

我的路線:

查看plaincopy to clipboardprint? 公共靜態無效的RegisterRoutes(RouteCollection路線)
{

// Ignore axd files such as assest, image, sitemap etc 
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 


routes.MapRoute("ServicesIndex", "services", new { controller = "Service", action = "Index" }); 

// Insurance Forms 
routes.MapRoute("InsuranceIndex", "insurance", new { controller = "Service", action = "Insurance" }); 
routes.MapRoute("InsuranceForm_Corporate", "insurance/corporate-health-insurance", new { controller = "Service", action = "InsuranceCorporate" }); 
routes.MapRoute("InsuranceForm_Life", "insurance/life-insurance", new { controller = "Service", action = "InsuranceLife" }); 
routes.MapRoute("InsuranceForm_Private", "insurance/private-health-insurance", new { controller = "Service", action = "InsurancePrivate" }); 

// Claim Forms 
routes.MapRoute("ClaimIndex", "claim", new { controller = "Service", action = "Claim" }); 
routes.MapRoute("ClaimForm_PersonalInjury", "claim/personal-injury-claim", new { controller = "Service", action = "PersonalInjury" }); 

// Surgery Forms 
routes.MapRoute("SurgeryIndex", "surgery", new { controller = "Service", action = "Surgery" }); 
routes.MapRoute("SurgeryForm_LaserEye", "surgery/laser-eye-surgery", new { controller = "Service", action = "LaserEye" }); 


routes.MapRoute("Cocoon.AboutUs", "about-us", new { controller = "Home", action = "AboutUs" }); 
routes.MapRoute("Cocoon.ContactUs", "contact-us", new { controller = "Home", action = "ContactUs" }); 

routes.MapRoute("Cocoon.Profile", "profile/{login}", new { controller = "Profile", action = "Index", login = "" }); 

routes.MapRoute( 
    "Default",            // Route name 
    "{controller}/{action}/{id}",       // URL with parameters 
    new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
); 

}

此外,CSS工作propoerly,它的指向同一個文件夾。 你知道發生了什麼事嗎?再次感謝你!

回答

0

一種方式是你的圖像源做到這一點從

../../Content/Images/cocoon_health_logo.png 

完整路徑來替代相對pathes到

/cocoonhealth/Content/Images/cocoon_health_logo.png 
0

<img height="59" width="228" title="Cocoon Health" alt="Cocoon Health" src="../../Content/Images/cocoon_health_logo.png"/> 

這告訴瀏覽器.. 。

../../Content/Images/cocoon_health_logo.png 
Go Up a folder level > Go Up a folder level > Content/Images/...png 

當您在url的末尾省略/時,實際上只需要上升一個級別,而不是兩個 - 因爲路由規則。

通過以下

<img height="59" width="228" title="Cocoon Health" alt="Cocoon Health" src="/cocoonhealth/Content/Images/cocoon_health_logo.png"/> 

你告訴瀏覽器...

/cocoonhealth/Content/Images/cocoon_health_logo.png 
/(start from the root) > cocoonhealth/Content/Images/cocoon_health_logo.png 

因此,這將有和沒有斜槓工作。

你也可以在HTML中使用BASE標籤,但是你應該首先閱讀它,否則它會讓你感到驚訝!