Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. IsUserInRole too slow - ASP.NET

IsUserInRole too slow - ASP.NET

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-net
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharp_k
    wrote on last edited by
    #1

    While debugging my slow application, I found the culprit is

    Roles.IsUserInRole

    It take from 3 sec to 9 second to execute. I found the reason it through the entire user list and calls other function, but it shouldn't be that slow to what I understand. My question is can it be made faster?

    OriginalGriffO D 2 Replies Last reply
    0
    • S sharp_k

      While debugging my slow application, I found the culprit is

      Roles.IsUserInRole

      It take from 3 sec to 9 second to execute. I found the reason it through the entire user list and calls other function, but it shouldn't be that slow to what I understand. My question is can it be made faster?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Your could implement a custom Role Provider[^] - I do - and then the responsibility is yours. Mine works by using a enum in the user info, so it is one access to the DB at most (normally none since the user profile is already downloaded).

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • S sharp_k

        While debugging my slow application, I found the culprit is

        Roles.IsUserInRole

        It take from 3 sec to 9 second to execute. I found the reason it through the entire user list and calls other function, but it shouldn't be that slow to what I understand. My question is can it be made faster?

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        Are you trying to determine if the current logged in user is in a role, i.e. for customising a page view? Have you tried using User.IsInRole against Roles.IsUserInRole? Don't know what you are doing, but the User. method should not need to iterate the entire user list (unless the inner working of the membership provides end up doing the same thing).

        Dave Find Me On: Web|Facebook|Twitter|LinkedIn


        Folding Stats: Team CodeProject

        S 1 Reply Last reply
        0
        • D DaveAuld

          Are you trying to determine if the current logged in user is in a role, i.e. for customising a page view? Have you tried using User.IsInRole against Roles.IsUserInRole? Don't know what you are doing, but the User. method should not need to iterate the entire user list (unless the inner working of the membership provides end up doing the same thing).

          Dave Find Me On: Web|Facebook|Twitter|LinkedIn


          Folding Stats: Team CodeProject

          S Offline
          S Offline
          sharp_k
          wrote on last edited by
          #4

          I am checking if the user in in role, he is allowed access to the page. If he is not, he is shown the error message. I have not trie User.IsInRole, somewhere I read, it give different result.

          D 1 Reply Last reply
          0
          • S sharp_k

            I am checking if the user in in role, he is allowed access to the page. If he is not, he is shown the error message. I have not trie User.IsInRole, somewhere I read, it give different result.

            D Offline
            D Offline
            DaveAuld
            wrote on last edited by
            #5

            From what you are saying, then the User.IsInRole is what you want, as the user is already logged into the system.

            Dave Find Me On: Web|Facebook|Twitter|LinkedIn


            Folding Stats: Team CodeProject

            S 2 Replies Last reply
            0
            • D DaveAuld

              From what you are saying, then the User.IsInRole is what you want, as the user is already logged into the system.

              Dave Find Me On: Web|Facebook|Twitter|LinkedIn


              Folding Stats: Team CodeProject

              S Offline
              S Offline
              sharp_k
              wrote on last edited by
              #6

              Is

              User.IsInRole

              faster and less expensive than

              Roles.IsUserInRole

              1 Reply Last reply
              0
              • D DaveAuld

                From what you are saying, then the User.IsInRole is what you want, as the user is already logged into the system.

                Dave Find Me On: Web|Facebook|Twitter|LinkedIn


                Folding Stats: Team CodeProject

                S Offline
                S Offline
                sharp_k
                wrote on last edited by
                #7

                Ok tried it. It did work but it also took 13 seconds to execute. Note that I have tracing enabled.

                D 1 Reply Last reply
                0
                • S sharp_k

                  Ok tried it. It did work but it also took 13 seconds to execute. Note that I have tracing enabled.

                  D Offline
                  D Offline
                  DaveAuld
                  wrote on last edited by
                  #8

                  Ok, so have you tried to profile your code and the Database. Sounds like you have some severe latency, probably in the database on disk. a) How many users in the user list? b) How many roles in the roles list? c) What sort of database are you using? d) Is the application and the database running on the same PC? Or is it distributed? What sort of connection is between them? e) Is their anything else that is slow in the application? f) Are you overriding any of the base methods and trying to role your own? These are some of the question you should be asking yourself. Next thing to do would be create a fresh vanilla application, add a couple of users and and a couple of roles and then run the IsInRole and IsUserInRole and see what difference you get.

                  Dave Find Me On: Web|Facebook|Twitter|LinkedIn


                  Folding Stats: Team CodeProject

                  S 1 Reply Last reply
                  0
                  • D DaveAuld

                    Ok, so have you tried to profile your code and the Database. Sounds like you have some severe latency, probably in the database on disk. a) How many users in the user list? b) How many roles in the roles list? c) What sort of database are you using? d) Is the application and the database running on the same PC? Or is it distributed? What sort of connection is between them? e) Is their anything else that is slow in the application? f) Are you overriding any of the base methods and trying to role your own? These are some of the question you should be asking yourself. Next thing to do would be create a fresh vanilla application, add a couple of users and and a couple of roles and then run the IsInRole and IsUserInRole and see what difference you get.

                    Dave Find Me On: Web|Facebook|Twitter|LinkedIn


                    Folding Stats: Team CodeProject

                    S Offline
                    S Offline
                    sharp_k
                    wrote on last edited by
                    #9

                    This is great advice. The fact is I have not worked a great deal with roles, profils etc and I just getting to know what providers are. 1. I have about 30 total users (max) 2. I have about 10 roles 3. SQL Server 2005 4. yes 5. No, when any page is access that has IsUserInRole, it is very slow 6. I am not overriding any function but thinking about it now. Something to note, this application was change from time to time so it also has old users which are about the same in numbers but obviously as upgraded the program, we created new users and the old ones are still in the database.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups