English 中文(简体)
Images not showing depending on the URL: with or without dash "/" in the end
原标题:

This is really weird. The images of my website are not showing properly. If a add a slash in the end of the url, they show up, otherwise, they don t. Take a look:

This is the link with dash in the end: http://jobbox.com.br/cocoonhealth/insurance/private-health-insurance/

To see the issue, delete the dash in the end…. the images will not show up anymore..

The funny thing is when I look at the html code, is exactly the same. I have some specific routes, but this issues is all over the website.

My routes:

view plaincopy to clipboardprint? public static void RegisterRoutes(RouteCollection routes)
{

// 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  
);  

}

Also, the CSS is working propoerly and it s pointing to the same folder. Do you know what s going on? Thank you again!

最佳回答

One of ways is to replace relative pathes with full path from

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

to

/cocoonhealth/Content/Images/cocoon_health_logo.png
问题回答

Your image sources do this:

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

This tells the browser...

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

When you omit the / from the end of the url, you actually only need to go up one level, not two - because of the routing rule.

By Using the following

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

You re telling the browser to...

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

So this will work with and without the slash.

You can also use the BASE tag in HTML, but you should read about it first as otherwise it will surprise you!





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签