Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2013, 08:46 PM   PM User | #1
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
Exclamation 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?
samuelito.mcf is offline   Reply With Quote
Old 02-01-2013, 04:05 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-04-2013, 06:12 PM   PM User | #3
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
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?
samuelito.mcf is offline   Reply With Quote
Old 02-04-2013, 09:06 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I'd have to see your folder structure to know.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-05-2013, 11:31 AM   PM User | #5
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
samuelito.mcf (02-05-2013)
Old 02-05-2013, 08:15 PM   PM User | #6
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
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
samuelito.mcf is offline   Reply With Quote
Old 02-05-2013, 08:19 PM   PM User | #7
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Quote:
Originally Posted by samuelito.mcf View Post
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!!!)
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 02-05-2013, 10:18 PM   PM User | #8
samuelito.mcf
New Coder

 
Join Date: Jan 2013
Location: Oregon
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
samuelito.mcf is an unknown quantity at this point
Quote:
Originally Posted by alykins View Post
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!
samuelito.mcf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:22 PM.


Advertisement
Log in to turn off these ads.