locked
restrict access to folder by Membership Role RRS feed

  • Question

  • User-1242214802 posted

    Hi All: I have an ASP.NET 2.0 membership website, with roles assigned to specific users. I've been using the following rules in web.config in each folder to restrict access:

    <?xml version="1.0"?>
    <configuration>
        <system.web>
          <authorization>
            <allow roles="admin,mgr"/>
            <deny users="*, ?"/>
          </authorization>
        </system.web>
    </configuration>
    

    what I just discovered is that a user that I've assigned to a different role, say "editors", can still access this folder after they log in. Shouldn't the ACL above prevent them from accessing an aspx file in that folder?

    Monday, May 9, 2016 9:07 PM

Answers

  • User-1636183269 posted

    Please try:

    <location path="FolderName">

        <system.web>
        <authorization>

        <allow roles="admin,mgr"/> //Allows users in admin & mgr role
        <deny users="*"/> // deny everyone else

        </authorization>
        </system.web>

    </location>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 10, 2016 12:43 AM

All replies

  • User-1636183269 posted

    Please try:

    <location path="FolderName">

        <system.web>
        <authorization>

        <allow roles="admin,mgr"/> //Allows users in admin & mgr role
        <deny users="*"/> // deny everyone else

        </authorization>
        </system.web>

    </location>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 10, 2016 12:43 AM
  • User-1716253493 posted

    AFAIK, to allow admin and manager only is like this

            <authorization>
              <allow roles="admin,mgr"/>
              <deny users="*" />
            </authorization>
            <authorization>
              <allow roles="admin,mgr"/>
              <allow users="someone"/>
              <deny users="*" />
            </authorization>

    Allow loged in user only

            <authorization>
                <deny users="?" />
            </authorization>

    To allow all (logedin or not)

            <authorization>
                <allow users="*" />
            </authorization>

    Tuesday, May 10, 2016 12:49 AM
  • User465171450 posted

    Also, keep in mind that these aren't ACLs as that is only NTFS based. Also, the rules work in conjunction with an authentication provider that you need to setup, usually the membership provider., Lastly, only files that are processed through the ASP.Net pipeline will be protected. Don't expect word docs or any other file there to be protected unless you have static content running through the pipeline .

    Tuesday, May 10, 2016 2:27 AM
  • User-1242214802 posted

    Also, keep in mind that these aren't ACLs as that is only NTFS based. Also, the rules work in conjunction with an authentication provider that you need to setup, usually the membership provider., Lastly, only files that are processed through the ASP.Net pipeline will be protected. Don't expect word docs or any other file there to be protected unless you have static content running through the pipeline .

    Hi Mark: I'm using the ASPNET 2.0 Membership and Roles providers.

    With my configuration above, a user in the "editors" role is still able to access ASPX files in this folder.

    My access rules are in a web.config in the folder.

    Tuesday, May 10, 2016 2:44 PM
  • User-1242214802 posted

    Please try:

    <location path="FolderName">

        <system.web>
        <authorization>

        <allow roles="admin,mgr"/> //Allows users in admin & mgr role
        <deny users="*"/> // deny everyone else

        </authorization>
        </system.web>

    </location>

    Thanks Sandeep...I tried it and it made no difference. Bear in mind that the web.config file with the authorization rules is in the same folder I'm trying to protect, so I am not user the "location path"

    Tuesday, May 10, 2016 2:47 PM
  • User475983607 posted

    It's been a long time since I used ASP Membership provider but what you have shown should work.  Have you verified the user is not in the admin or mgr role?  

    Tuesday, May 10, 2016 2:52 PM
  • User-1242214802 posted

    Thanks Sandeep...I tried it and it made no difference. Bear in mind that the web.config file with the authorization rules is in the same folder I'm trying to protect, so I am not user the "location path"

    '

    Sandeep: I tried deleting the web.config from the child folder, and moving the authorization rules to the root web.config using the "location" parameter, and this seemed to work.

    Tuesday, May 10, 2016 3:02 PM