CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   ASP (http://www.codingforums.com/forumdisplay.php?f=8)
-   -   Nesting pages in folders. (http://www.codingforums.com/showthread.php?t=286834)

samuelito.mcf 01-31-2013 08:46 PM

Nesting pages in folders.
 
In my aspx.net site my master page contains the links to all stylesheets. Whenever I try to put one of my pages that use that master page in a subfolder they look right html wise but none of the styling is passed over and all pictures in the master page don't appear either. I know this is a problem with how I'm linking to the stylesheet and the images but I don't know how to fix it. It's assuming that everything should be in the same folder as the page but that isn't the case...Has anyone else experienced this?

Old Pedant 02-01-2013 04:05 AM

Why are you surprised?

If you have folders set up as
Code:

    /root
        main.aspx
        /css
            master.css
        /script
            code.js
        /subdir
            another.aspx

Then even by the rules of Windows paths, the way to get to /css from "main.aspx" is via "./css/master.css" where as from "another.aspx" it would be "../css/master.css"

So you either need to specify the correct *relative* path from your "another.aspx" file or you must specify an *absolute* path that is relative to the root of your site.

If your /root directory (or whatever it is named, but corresponding to the above picture) is also your web root directory, then you can always get to "master.css" from *ANY* page by using "/css/master.css". That leading "/" means "start at the root directory".

There are other solutions, especially if you control setting up virtual directories on the server, but that's the meat of it.

samuelito.mcf 02-04-2013 06:12 PM

I changed all the paths to have ../ in front of them in my master page. So then it worked for the sub pages but stopped working for the pages located under the root. Not sure why. So then I just created a different master page for any pages in a subfolder and it is working just how I want it. I just don't know if that is the best way to do it?

Old Pedant 02-04-2013 09:06 PM

I'd have to see your folder structure to know.

alykins 02-05-2013 11:31 AM

this link kinda describes the idea... what you are dealing with is absolute vs relative paths (in your case you are doing relative)... I always find this to be a pain in the ***, and I have never cared to 'learn it'... I know the concept behind it, but what I do is (if) I am starting a new project, I get the skeleton working first with my master page and all the children, and then go to work on the rest of the site. Once you understand the theory behind it you can either learn it, or fiddle with it from time to time as I do.

basically it boils doen to this...
absolute paths (which you are not using) would be something like this
Code:

"C:\\inetpub\\wwwroot\\website1\\CSS\\MyStyles.css"  or
@"C:\users\me\VS20##\Projects\MyProject\website1\MyStyles.css"

As you can see they are hard coded paths. These are generally less favorable as they require the server to be exactly as coded (hard coded values can cause a lot of problems)

then there are relative paths which looks like
Code:

"./CSS/MyStyles.css" or
"../Images/MyImage.png"

See the difference? They rely on the projects structure not the box they are sitting on, so they will always be right (also relative has forward slashes */* as opposed to absolute's backslashes *\*). Old Pedant may be able to clarify the technicalities of the dot's and slashes (again I never care to 'learn' them, I just spend the few minutes tinkering with them- but I also don't do a lot of front end work either :P)

hope that helps some

samuelito.mcf 02-05-2013 08:15 PM

Ok I see now. I'm still not sure why when I add the ../ it only works for some and not others. But I did solve the problem by using separate master pages

alykins 02-05-2013 08:19 PM

Quote:

Originally Posted by samuelito.mcf (Post 1311146)
Ok I see now. I'm still not sure why when I add the ../ it only works for some and not others. But I did solve the problem by using
Code:

separate master pages

I would not do that. That is the opposite of coding theory (make consolidated reusable code). Creating and entirely new master page to accomodate a relative path is.... bad. Play around with the dot's and slahses until you get it right. That's why I said do it first, before you have invested a lot into the project and start-ups for the app are quick. You also need to make sure you are clearing your cache. The simplest way I have found to do this is to put a simple .png in the folders I want to map- then it will either load the image or it won't... then once everything is kosher, remove the image and links to it (but copy the path structure!!!)

samuelito.mcf 02-05-2013 10:18 PM

Quote:

Originally Posted by alykins (Post 1311149)
I would not do that. That is the opposite of coding theory (make consolidated reusable code). Creating and entirely new master page to accomodate a relative path is.... bad. Play around with the dot's and slahses until you get it right. That's why I said do it first, before you have invested a lot into the project and start-ups for the app are quick. You also need to make sure you are clearing your cache. The simplest way I have found to do this is to put a simple .png in the folders I want to map- then it will either load the image or it won't... then once everything is kosher, remove the image and links to it (but copy the path structure!!!)

Yes, that's what I figured. I'll continue to fool around with it. Thanks for the suggestions!


All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.