Application_AuthenticateRequest

Discussion in 'ASP .Net' started by =?Utf-8?B?RGlmZmlkZW50?=, Oct 27, 2006.

  1. 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!!!!
     
    =?Utf-8?B?RGlmZmlkZW50?=, Oct 27, 2006
    #1
    1. Advertising

  2. Hi,

    Diffident wrote:
    > 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.


    Note that one postback (or simply loading one page) may create many
    requests. First one request is sent for the main (HTML, ASPX...) page.
    Then the browser parses the page and for each external object found
    (included JavaScript files, CSS files, images, other OBJECTs, ...) a new
    request will be sent (except if a valid cached version is found).

    If you want to see for sure what is happening on the line, I recommend
    the tool Fiddler (http://www.fiddlertool.com/fiddler/) which will show
    each request. That should help finding the "problem" (if there is one)
    or to improve your design if needed.

    HTH,
    Laurent
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Oct 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Kingscott
    Replies:
    0
    Views:
    484
    Mike Kingscott
    Jun 30, 2003
  2. Nugs

    Application_AuthenticateRequest

    Nugs, Apr 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,216
  3. =?Utf-8?B?ZGFubWFuMjI2?=

    Application_AuthenticateRequest cannot read Session variable

    =?Utf-8?B?ZGFubWFuMjI2?=, Apr 18, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    12,468
    Brock Allen
    Apr 18, 2005
  4. Alessio Brizi

    Application_AuthenticateRequest Problem

    Alessio Brizi, Jul 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    594
    Alessio Brizi
    Jul 8, 2005
  5. =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=

    When does Application_AuthenticateRequest fires?

    =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=, Dec 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    10,697
    Brock Allen
    Dec 22, 2005
Loading...

Share This Page