G
Guest
Hello All,
Does the Application_AuthenticateRequest event get fired for every request
made to the application? According to my understanding, YES it does get fired
for each and every request. Please correct me if I am wrong.
But does the event get fired multiple times for the same request? I do not
understand why in my application is it being called multiple times for the
same request. Every time it is retrieving the role information for the user
and associating that with the principal.
I would like to get recommendations/pointers from you folks as to what I am
doing wrong and also best practices. Below please find the code for this
event.
if ( HttpContext.Current.User != null )
{
string PrincipalIdentityName =
HttpContext.Current.User.Identity.Name.ToLower();
System.Web.Security.FormsIdentity id;
id =
(System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
//Added on October 26, 2006
string FormsIdentityName = id.Name.ToLower();
String[] myRoles = new String[10];
int i = 0;
if(HttpContext.Current.User.Identity.Name.ToUpper() ==
"SuperAdmin".ToUpper())
{
myRoles = "PowerUser";
i++;
}
if(objRolesservice.IsRegionalUser(PrincipalIdentityName))
{
myRoles = "RegionalUser";
i++;
}
HttpContext.Current.User = new
System.Security.Principal.GenericPrincipal(id, myRoles);
}
The above loop is being executed multiple times for the same request. I
would like to optimize it. All I am doing in the loop is retrieving his role
information.
At the beginning of the loop I have a condition which is
if ( HttpContext.Current.User != null ) do I need to change this condition
to something else so that after role information is associated to principal,
this loop is not executed multiple times for the same request?
Thanks for all your pointers!!!!
Does the Application_AuthenticateRequest event get fired for every request
made to the application? According to my understanding, YES it does get fired
for each and every request. Please correct me if I am wrong.
But does the event get fired multiple times for the same request? I do not
understand why in my application is it being called multiple times for the
same request. Every time it is retrieving the role information for the user
and associating that with the principal.
I would like to get recommendations/pointers from you folks as to what I am
doing wrong and also best practices. Below please find the code for this
event.
if ( HttpContext.Current.User != null )
{
string PrincipalIdentityName =
HttpContext.Current.User.Identity.Name.ToLower();
System.Web.Security.FormsIdentity id;
id =
(System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
//Added on October 26, 2006
string FormsIdentityName = id.Name.ToLower();
String[] myRoles = new String[10];
int i = 0;
if(HttpContext.Current.User.Identity.Name.ToUpper() ==
"SuperAdmin".ToUpper())
{
myRoles = "PowerUser";
i++;
}
if(objRolesservice.IsRegionalUser(PrincipalIdentityName))
{
myRoles = "RegionalUser";
i++;
}
HttpContext.Current.User = new
System.Security.Principal.GenericPrincipal(id, myRoles);
}
The above loop is being executed multiple times for the same request. I
would like to optimize it. All I am doing in the loop is retrieving his role
information.
At the beginning of the loop I have a condition which is
if ( HttpContext.Current.User != null ) do I need to change this condition
to something else so that after role information is associated to principal,
this loop is not executed multiple times for the same request?
Thanks for all your pointers!!!!