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. The Lounge
  3. IsUserInRole too slow - ASP.NET

IsUserInRole too slow - ASP.NET

Scheduled Pinned Locked Moved The Lounge
questioncsharpasp-net
12 Posts 6 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?

    S R L K T 5 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?

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      sharp_k wrote:

      My question is can it be made faster?

      Would I be some pedantic jerk, I would say:

      And my question is : is this the ASP.Net forum ?

      [Edit] And even in the ASP.Net forum, I doubt this can be answered with so little background information [/Edit]

      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?

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        might be best asked here Codeproject asp.net forum[^]

        Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

        S 1 Reply Last reply
        0
        • S Simon_Whale

          might be best asked here Codeproject asp.net forum[^]

          Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

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

          Thanks. Did will delete this one.

          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?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Find out what part exactly takes so much time. Perhaps there are many entries in the table that assigns the roles to the users. That can slow down the queries and in that case a lot can be done by trying to add or optimize the indices of the tables involved.

            I'm invincible, I can't be vinced

            S 1 Reply Last reply
            0
            • L Lost User

              Find out what part exactly takes so much time. Perhaps there are many entries in the table that assigns the roles to the users. That can slow down the queries and in that case a lot can be done by trying to add or optimize the indices of the tables involved.

              I'm invincible, I can't be vinced

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

              I dont have SQL profiler. But well made point. Will look into it. The total users in my app is less than 100 anyhow. Shouldn't be taking that long! Will investigate.

              L 1 Reply Last reply
              0
              • S sharp_k

                I dont have SQL profiler. But well made point. Will look into it. The total users in my app is less than 100 anyhow. Shouldn't be taking that long! Will investigate.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                And if that does not work, you can still try to reduce the calls by getting the roles assigned to the current user and buffering the result. The simple way to do that would be to send off the query early (let's say in Page_Load()) and simply put the result into a member variable of the page, so that you can use it until the page's lifecycle ends.

                I'm invincible, I can't be vinced

                S 1 Reply Last reply
                0
                • L Lost User

                  And if that does not work, you can still try to reduce the calls by getting the roles assigned to the current user and buffering the result. The simple way to do that would be to send off the query early (let's say in Page_Load()) and simply put the result into a member variable of the page, so that you can use it until the page's lifecycle ends.

                  I'm invincible, I can't be vinced

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

                  I am using Page_load currently. The code came from previous developer. There is a lot of calling for IsUserInRole so that definitely can improve performance if I remove them. But I am looking for a more elegant solution now that solves the problem of slow IsUserInRole. If not, your suggestion would be my best bet.

                  L 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?

                    K Offline
                    K Offline
                    Keith Barrow
                    wrote on last edited by
                    #9

                    sharp_k wrote:

                    My question is can it be made faster?

                    Yes, as can getting an answer to your question: by posing it in the correct forum.

                    Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                    -Or-
                    A Dead ringer for Kate Winslett[^]

                    1 Reply Last reply
                    0
                    • S sharp_k

                      I am using Page_load currently. The code came from previous developer. There is a lot of calling for IsUserInRole so that definitely can improve performance if I remove them. But I am looking for a more elegant solution now that solves the problem of slow IsUserInRole. If not, your suggestion would be my best bet.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Reducing the number of queries and buffering the result (if needed) already is far less wasteful. Also you should look what the other guy needed so many queries for. Sounds like he smeared the logic all over the place. This surely can be consolidated or replaced by a more efficient logic. Repeatedly calling IsUserInRole sounds a little too primitive and wasteful.

                      I'm invincible, I can't be vinced

                      S 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?

                        T Offline
                        T Offline
                        TheGreatAndPowerfulOz
                        wrote on last edited by
                        #11

                        Yes, cache the answer. Or find another way.

                        If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
                        You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

                        1 Reply Last reply
                        0
                        • L Lost User

                          Reducing the number of queries and buffering the result (if needed) already is far less wasteful. Also you should look what the other guy needed so many queries for. Sounds like he smeared the logic all over the place. This surely can be consolidated or replaced by a more efficient logic. Repeatedly calling IsUserInRole sounds a little too primitive and wasteful.

                          I'm invincible, I can't be vinced

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

                          What basically the logic is right now, every page check for IsUserInRole and not just for one role. There are pages which can be accessed by two or three roles. If the user is in that role, he is allowed access otherwise not. It does not seem like that wasteful. But since IsUserInRole is slow, it needs to be made better. Ever page you visit is slow just because of it! So I can see now if I use cache even for single user, at least all the subsequent clicks will be faster.

                          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