图片未显示取决于URL:最后带有或不带短划线“/”

时间:2009-11-20 11:18:21

标签: asp.net-mvc asp.net-mvc-routing

这真的很奇怪。我网站的图片显示不正确。如果在URL的末尾添加斜杠,它们会显示,否则,它们不显示。看看:

这是与破折号的链接: http://jobbox.com.br/cocoonhealth/insurance/private-health-insurance/

要查看问题,请在最后删除短划线....图像不会再出现..

有趣的是,当我查看HTML代码时,情况完全一样。我有一些具体的路线,但这个问题遍布整个网站。

我的路线:

查看plaincopy到clipboardprint? public static void 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正在按比例工作,它指向同一个文件夹。 你知道发生了什么吗?再次感谢你!

2 个答案:

答案 0 :(得分:0)

其中一种方法是用

的完整路径替换相对路径
../../Content/Images/cocoon_health_logo.png 

/cocoonhealth/Content/Images/cocoon_health_logo.png

答案 1 :(得分: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

当您从网址末尾省略/时,实际上只需要上升一级而不是两级 - 因为路由规则。

使用以下

<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标记,但是您应该先阅读它,否则会让您感到惊讶!