skip to Main Content

No particular error but I’m working on an assignment and when I use ../../Style/index.css the styling does not render to the master page it is linked to. But when I change it to ~/Style/index.css it renders the styling. Is there a difference between the two. I’m new to asp.net

 <link href="~/Content/Master.css" rel="stylesheet" type="text/css" />

as apposed to

 <link href="../../Content/Master.css" rel="stylesheet" type="text/css" />

3

Answers


  1. this link always show the absoulute patch from the root of website, doesn’t matter in what folder it is situated

    <link href="~/Content/Master.css" rel="stylesheet" type="text/css" />
    

    but this link shows relative path, and depends on the folder where page with this link is situated

     <link href="../../Content/Master.css" rel="stylesheet" type="text/css" />
    

    the page with this link supposed to be in two nested folders from the root. if page moves to somewhere else, the link will be invalid

    Login or Signup to reply.
  2. The main difference between absolute and relative paths is that absolute URLs always include the domain name of the site with http://www. Relative links show the path to the file or refer to the file itself.

    A relative URL is useful within a site to transfer a user from point to point within the same domain.

    <link href="../../Content/Master.css" rel="stylesheet" type="text/css" />
    

    Absolute links are good when you want to send the user to a page that is outside of your server.

    <link href="~/Content/Master.css" rel="stylesheet" type="text/css" />
    

    Developers often make life easier for themselves by using relative links for their site. When there are hundreds of pages on a resource, it is tedious and time-consuming to write the entire path for each one. Instead, indicating a point on the site map will make it clear that the page belongs to a specific server, so in general it’s consider best practice to use the absolute path.

    Login or Signup to reply.
  3. This doing this:

    tap windows key, type in command

    select the top suggest – command prompt.

    You see this:

    enter image description here

    now type in cd .. (two dots)

    You get this:

    enter image description here

    Note how I dropped down ONE folder.

    So, ".." means ONE folder lower then where ever I am currently. It just a way to use relative addressing – no matter where the folder (or web site) is running.

    However, " ~/" means start from the root folder of the web site and work your way upwards from that starting folder. You might be a few folders deep. You one the "one lower" folder ../ or maybe two folders lower ../../Pictures

    So the two dots? Goes all the way back to the first PC, and DOS command prompt.

    When used in a path name, it simply means ONE folder below the current folder.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search