0

In my web.config I have this authentication setting:

<authentication mode="Forms">
            <forms loginUrl="login.aspx" name="signin" path="/" protection="All" timeout="525600">
            </forms>
        </authentication>
<authorization>
            <deny users="?"/>
        </authorization>

For some reason, if I comment it out I can see my website just perfectly with all the assets (js, css, images), but if I uncomment it, none of the assets can be reached, instead it just redirects to login page.

anthonypliu
  • 12,179
  • 28
  • 92
  • 154

4 Answers4

2

here is a nice in-depth article for you. basically, it says you can configure this in your web.config by adding <location> blocks like so:

<!-- file level access -->
            <location path="default1.aspx">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>
<!--  folder access (and its contents)  -->
            <location path="subdir1">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>
    </configuration>

from this KB article and a bit more info here.

Muad'Dib
  • 28,542
  • 5
  • 55
  • 68
1

Use Location element.

   <location path="~/css">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • It seems like you're just providing a sample but wouldn't it be better with * instead of ? to provide some help? – Asken Oct 19 '11 at 08:26
0

Looks like assets are served via ASP.NET pipeline. Check the following topic:

Prevent IIS from serving static files through ASP.NET pipeline

Community
  • 1
  • 1
Artem Koshelev
  • 10,548
  • 4
  • 36
  • 68
0

The

    deny users="?"

is saying that no unauthenticated users can access the site at the root and it will redirect to the login page. I normally always keep the root (/) public (allow users="*") and have protected folders set up using the location. That will keep images, css and script folders under the root available for public access.

This should probably work for you if you can move your protected pages into another folder easily:

<configuration>
    <system.web>
        <authentication mode="Forms">
            <forms loginUrl="login.aspx" name="signin" path="/" protection="All" timeout="525600">
            </forms>
        </authentication>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>

    <location path="protected">
        <authorization>
            <deny users="?" />
        </authorization>
    </location>
</configuration>
Asken
  • 7,679
  • 10
  • 45
  • 77