2009-11-20 19 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标签,但是你应该首先阅读它,否则它会让你感到惊讶!