ASP.NET page is not loading CSS styles

前端 未结 6 1019
梦毁少年i
梦毁少年i 2020-12-16 14:12

This is a simple website in ASP.NET with C# using VS 2010. I have following directory structure for this project:

6条回答
  •  庸人自扰
    2020-12-16 15:01

    The stylesheets included in your master page are using relative paths.

    Specify your stylesheet links with runat=server and prefix them with the virtual web root path (~):

    
    

    OR:

    
    

    But keep in mind that the first option is recommended. The second will not work when you publish your site in a virtual directory.

    After last comment...

    The image URL's in CSSs should be updated as well, in order to not use relative paths or do any path traversal (../).

    background: #fff url(images/img01.jpg) repeat-x left top;

    For this option you will need to move the images folder inside the Styles folder (it's a good practice to do so).

    Final update:

    Looks like that the head element also needs to be runat=server in order for ASP.NET relative paths (~) to work within link elements with runat=server.

提交回复
热议问题