Rees Guimbeau
Rees Guimbeau

Reputation: 11

Web.config error with <authorization> node

When I add <authorization> it displays the page but without the css. Anyone has an idea why??

Here is my web.config

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="UomDBConnectionString1"
         connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\UomDB.mdf;Integrated Security=True;User Instance=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx" timeout="2880" />
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>
</configuration>

If I remove it display the page with the css.

Upvotes: 1

Views: 600

Answers (4)

gaijintendo
gaijintendo

Reputation: 423

I had these symptoms, but for some reson my issue was having set a single mimetype:

<system.webServer>
   <staticContent>
      <mimeMap fileExtension=".pdf" mimeType="application/pdf" />
...
</staticContent>

From however my machine is set up, this seemed to preculde the use of any image, or css file.

I assume there is a default set, and by specifying a mimetype, you no longer implicitly have the other types. Dropping that, fixed it for me.

Upvotes: 0

Bhushan Firake
Bhushan Firake

Reputation: 9458

Seems your CSS is protected under the authorization.To allow an unauthenticated user to see your .css files (or any other file/directory) you can add a location element to your web.config file pointing to the .css file.

<configuration>
    <location path="App_Themes/Default/YourFile.css">
        <system.web>
            <authorization>
                <allow users="*"/>
            <authorization>
        <system.web>
    <location>
<configuration>

Upvotes: 1

coder
coder

Reputation: 13248

May be your css and images folders are under restricted area..

you need to allow access to these files in this forms authentication code in web.config.

This is how you do:

 <location path="default.aspx">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>

  <location path="Home">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>

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

  <location path="Scripts">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>

  <location path="images">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>

Took from here

Upvotes: 1

IrishChieftain
IrishChieftain

Reputation: 15253

You need to make sure that you're CSS is not in another protected folder.

Upvotes: 0

Related Questions