Search code examples
asp.netcssstylesheet

StyleSheet not working properly in ASP.NET


the style sheet is not working properly unless I make a

   <style type="text/css">

tag

and put in the aspx page i want to apply the style.

This happens with every page i want to apply the style sheet on.

My style sheet is located inside the folder "Styles" in the root directory of the project.

I am referencing the style like this

<link href="Styles/StyleSheet.css" rel="stylesheet" type="text/css" />

Solution

  • I think the problem is with path of your CSS files. If Styles folder is located in the root of your web site. add a "/" to start of css file path. like this:

    <link href="/Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
    

    The above sample says: There is a Styles folder in root of my web site and inside that there is a file named StyleSheet.css

    But in your sample it says: There is a Styles folder (Not in root) inside current directory (based on current URL).

    So with url like this:

    http://localhost/Admin/Users/Manage.aspx
    

    It will search for css file in this address:

    http://localhost/Admin/Users/Styles/StyleSheet.css
    

    but adding a slash to start of css address may solve this problem.

    UPDATE:

    Check if Styles folder is a secured folder or not. Try entering css file path into your browser and if you were redirected to your login page, put a Web.Config file in your Styles directory with this content:

    <configuration>
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </configuration>