locked
Content/site.css mistery RRS feed

  • Question

  • User-1765853593 posted

    Hi,

    It soudns like a mistery for me. The default Site.Master has this markup:

     

    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    </head>
      

    I expected the link href will always be static as it is set: "../../Content/Site.css"

    It means pages like these would have the CSS:

    • Home/One/Index.aspx
    • Home/Two/Index.aspx
    • Product/One/Edit.aspx 

    and I expected following ones would not have CSS because of broken link:

    • Home/Index.aspx
    • Home/Two/Three/Index.aspx
    • Product/Category/One/Edit.aspx

    but o wondered that the HREF of the link has always been generated correctly!

     

    How come? link has even no runat="server" attribute?

    I probably don't know something related to Master Pages.

     

    Thanks,
    Dmitriy.

    Tuesday, January 6, 2009 7:35 PM

Answers

  • User878321963 posted
    This was news to me as well. I didn't know that .NET would rewrite URLs in a MasterPage for HTML elements - it's always fun to learn something new!
    Apparently, this is called "URL Rebasing", and happens for controls marked with runat=server, and controls in the head (I assume the head needs to be marked with runat=server for this to work, which yours is).

    Here is an article that explains just about anything you would want to know about MasterPages. It is a little dated, but the content is still very good.

    http://www.odetocode.com/articles/450.aspx
    The section talking about URL Rebasing is under the heading "Break Some URLs"

    I hope that helps!
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2009 6:49 PM

All replies

  • User-504499122 posted

     Hi Dimitriy,

    You mentioned the following link tag is inside the master page, so it does not matter where the content pages are. The path is relative to the master page, not the actual content page. Thats why you do not see any problem 

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

     

    Tuesday, January 6, 2009 9:24 PM
  • User-1765853593 posted

    Hi,

    So it means when ASP.NET renders the page with MasterPage it converts all the link's HREFs to the ones related to the request.
    That would be fine if LINK had runat="server", but it is STATIC and I expect it to be non-changeable.

    In this case I should also know what else is done behind the scene when a master page is rendered (are the a@HREf, img@src etc converted as well?).

    Cheers,
    Dmitriy.

    Wednesday, January 7, 2009 6:22 PM
  • User878321963 posted
    This was news to me as well. I didn't know that .NET would rewrite URLs in a MasterPage for HTML elements - it's always fun to learn something new!
    Apparently, this is called "URL Rebasing", and happens for controls marked with runat=server, and controls in the head (I assume the head needs to be marked with runat=server for this to work, which yours is).

    Here is an article that explains just about anything you would want to know about MasterPages. It is a little dated, but the content is still very good.

    http://www.odetocode.com/articles/450.aspx
    The section talking about URL Rebasing is under the heading "Break Some URLs"

    I hope that helps!
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 7, 2009 6:49 PM
  • User-1765853593 posted
    Thanks a lot. It clears everything now. Turns out that mystery is a magic :)
    Wednesday, January 7, 2009 11:38 PM