c# - Asp.net website very slow because of roles checkin on every page -


There are roles on my ASP.NET application. I have problems (I think). The problem uses every page role and permission in the application, so it uses the following functions in the page load

If the roles (see the ISUER Innerol ("Admin")) {// page display} other {// no}

I solved my problem with this question

but there are some differences 1. The above question uses WindowsTokenRoleProvider , I using SqlRoleProvider

of the above problem South, above solution does not work for me.

What I have done so far, and I am partially successful, I have received a class from SqlRoleProvider and in this function which is similar to the above question but modified I changed web.config That it looks like this

  & lt; RoleManager enabled = "true" cache ROLESInCookie = "true" cookieName = ". ASPR0L3S" cookieTimeout = "117" cookie sliding = "true" cookie protection = "all" createcentantcookie = "wrong" default provider = "custom sclerol provider" & Lt; Providers & gt; & Lt; Add name = "CustomRoll Provider" type = "CustomSkillRollProvider" connection StringName = "PEGConn" applicationName = "/ CRM" /> & Lt; / Providers & gt; & Lt; / RoleManager & gt;   

This is the function within my class, which receives (only executed at user's login)

  public override string [] GetRolesForUser (string User name) {// will list the roles in which the user list & lt; String & gt; Roles = null; Create a unique cache key for the // user string key = string.concount (username, "base, appnname); // get the cache for current session cache cache = HttpContext.Current.Cache; // cached roles for the user Receive if (cache [key]! = Null) {roles = new list & lt; string & gt; (cache [key] as string []);} // was the list of role for the user in the cache? If (roles == blank) {string [] AllRoles = GetAllRoles (); role = New list & lt; string & gt; (); // For the role of each system, determine that the user is a member of the role of the role (string role in AllRoles) (if (base.IsUserInRole (username , Role)) {roles.Add (role);}} // Cache roles for 1 hour cache Insert (keys, rows.Tower (), blank, date time.Now.Adhors (1), cache Lifting of lifting);} // Roles for return withdrawal Return List. ToArray ();}   

The problem occurs when the roles are called. The ISUER Inroll function calls the old

System.Web.Security.Roles IsUserInRole

I have surrendered this function to my new class but it is never executed. I'm basically caching all the roles so that every page can be refreshed, not all roles are searched from the beginning.

Do I need to get another class from System.Web.Security .Roles.IsUserInRole ? Someone has done it.

Each page takes about 4-8 seconds to fresh, which is too long. Code VS is in 2008, C # 3.5

I think this is a basic problem with your application Can also hide the design. You should not subscribe to the dry principle, do not repeat yourself, that is, do not repeat the same look / code on each page. I suggest using the variables of the session so that you can "cache" to see these expensive roles. Here's a quick guide to using session variables:

Note one side. I think that you are using cookies to store these 'roles', it does not look very safe, so I think security is not the main goal of this exercise.

Comments