user478636
user478636

Reputation: 3424

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" />

Upvotes: 0

Views: 20169

Answers (4)

RoastBeast
RoastBeast

Reputation: 1115

To add to what Afshin Gh mentioned in his/her answer - if your Styles folder is in a secured folder you could also add something like

<location path="Styles">
<system.web>
    <authorization>
      <allow users="*"/>
    </authorization>
  </system.web>
</location>

to your website's main Web.config file.

Upvotes: 1

Dev8055
Dev8055

Reputation: 33

I had the same issue with my ASP.Net application not loading CSS and Images. Updated the Web.config to allow anonymous user to access theses files or folder in which they are stored.

In two possible way you can give permissions:

1) Update/Add in the root Web.config file with RoastBeast code above. 2) Add separate Web.config file to that specific folder (i.e. Styles, Images) and give anonymous access.

Upvotes: 0

IrishChieftain
IrishChieftain

Reputation: 15253

Simply open the Web Form in code view and drag the style sheet from Solution Explorer into the form.

Upvotes: 1

Afshin Gh
Afshin Gh

Reputation: 8188

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>

Upvotes: 9

Related Questions