lack of understanding of principals, identities, and context

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Re: lack of understanding of principals, identities, and context

    HttpContext is request specific (recreated for every request) and therefore
    you'd need to set the user on every request that means creating instance of
    FiveADayPrincipal and assigning it to the Context.User.

    Therefore there exists methods in Global.asax as
    Application_AuthenticateRequest as they are called on every request and can
    be used to set the Principal.

    --
    Teemu Keiski
    MCP,Designer/Developer
    Mansoft tietotekniikka Oy
    [url]http://www.mansoft.fi[/url]

    AspInsiders Member, [url]www.aspinsiders.com[/url]
    ASP.NET Forums Moderator, [url]www.asp.net[/url]
    AspAlliance Columnist, [url]www.aspalliance.com[/url]


    "Bryan Ax" <bax@kleinbuendel.com> kirjoitti viestissä
    news:7aa793c0.0308191246.38e44793@posting.google.c om...
    > Currently, on a login page, I'm doing the following after validating
    > login information:
    >
    > //user is a custom object we have.
    > //FiveADayPrincipal is a class that implements the IPrincipal
    > interface, and extends it for some additional functionality.
    >
    > Context.User = new FiveADayPrincipal(user);
    > this.Response.Redirect("default.aspx");
    >
    > Now, on the default.aspx page, I do the following:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > //check to make sure user is logged in.
    > bool auth = Context.User.Identity.IsAuthenticated;
    >
    > string name = this.Context.User.Identity.Name;
    >
    > if (! this.Context.User.Identity.IsAuthenticated)
    > {
    > this.Response.Redirect("/Login.aspx");
    > }
    > }
    >
    > I'm testing the results with those first two lines, and finding that
    > the user is not authenticated. However, when I change the line
    > this.Response.Redirect("default.aspx") to use this.Server.Transfer
    > instead, it works fine. Does the context get lost when using
    > redirects? I know people have said to use Server.Transfer for various
    > reasons, but I have a bunch of legacy code using Response.Redirect. In
    > order to protect security, am I going to need to change all those to
    > Server.Transfer to keep the Context alive? Or should I just avoid
    > using the Context.User.Identity.IsAuthenticated and instead test for
    > some type of session object that stores my custom user (currently, the
    > user is encapsulated in the custom Identity object)?
    >
    > Sincerely,
    >
    > Bryan Ax

    Teemu Keiski Guest

  2. Similar Questions and Discussions

    1. is anybody a bit let down about the lack of fanfare?
      Is anybody a bit let down about the lack of fanfare? The CFMX 7 release didn't seem to stay on the MM homepage very long and it never did get its own...
    2. Lack of info
      IM not ranting, IM pointing out that I have looked on the website and the FAQ is a joke and help from other sources is either buy something or as...
    3. extra identities
      Repairing XP Did Not Work,tried both Recovery Console and "repair" after license agreement. Now, due to reinstall and attempts to transfer...
    4. Lack of support by MS
      I have never been so appalled by the lack of MS support until XP. It is already claiming that I have exceeded my free support references. This...
    5. XP Outlook Express identities
      I recently had a hard-drive failure. I took the opportunity to buy a new bigger drive. Most of my backup was on my primary drive while systems were...
  3. #2

    Default Re: lack of understanding of principals, identities, and context

    > HttpContext is request specific (recreated for every request) and
    therefore
    > you'd need to set the user on every request that means creating instance
    of
    > FiveADayPrincipal and assigning it to the Context.User.
    >
    > Therefore there exists methods in Global.asax as
    > Application_AuthenticateRequest as they are called on every request and
    can
    > be used to set the Principal.
    So, if you are not using cookies, what is the best way to maintain state
    across a session? Do you set a session variable, say UserID, when the user
    logs in, and get the user information from this in the Global.asax
    Application_AuthenticateRequest each time to repopulate the context object?

    If you've gone this far with rolling your own solution, why bother with
    setting the MS context authentication stuff on each Global.asax
    Application_AuthenticateRequest, but instead just check the filepath using
    HttpContext.Current.Server.MapPath() (or whatever else you need to configure
    you authentication framework) and set roles and permissions accordingly in
    your own framework (eg session variables)?

    It would not be too heavy (only involving two or three session variables, eg
    userID, role, and permissions).

    What would be the pros and cons of this approach?

    MS have not made their forms authentication framework intuitive at all IMO.

    Lauchlan M


    Lauchlan M Guest

  4. #3

    Default Re: lack of understanding of principals, identities, and context

    It really concerns things when authenticating and/or authorizing are hard
    customized and it isn't just Forms Authentication specific. In simple case I
    don't see anything wrong with simple session solution but framework support
    is one main thing why I'd avoid it.

    Other thing when it is used would be when you use role-based authentication.
    In that case you could let Forms Authentication to handle the authenticating
    and store roles into the login cookie (UserData property of
    FormsAuthenticationTicket). Then on Application_Authenticaterequest it is
    checked if Request.IsAuthenticated=true (login cookie exists in case Forms
    auth) and then roles read from cookie and again custom IPrincipal populated
    with information regarding roles.

    In case when cookies are not allowed, you still can use Forms Authentication
    (I think I have explained it to you earlier). In that case the
    FormsAuthenticationTicket is persisted in the Querystring, but the drawback
    was with keeping this on every page so that login information is persisted
    when user navigates on the site. But if you want to avoid this drawback,
    getting to use cookieless sessions is one solution and that leads to the
    solution you discussed about.

    --
    Teemu Keiski
    MCP,Designer/Developer
    Mansoft tietotekniikka Oy
    [url]http://www.mansoft.fi[/url]

    AspInsiders Member, [url]www.aspinsiders.com[/url]
    ASP.NET Forums Moderator, [url]www.asp.net[/url]
    AspAlliance Columnist, [url]www.aspalliance.com[/url]


    "Lauchlan M" <LMackinnon@Hotmail.com> kirjoitti viestissä
    news:%23asS0TwZDHA.1280@tk2msftngp13.phx.gbl...
    > > HttpContext is request specific (recreated for every request) and
    > therefore
    > > you'd need to set the user on every request that means creating instance
    > of
    > > FiveADayPrincipal and assigning it to the Context.User.
    > >
    > > Therefore there exists methods in Global.asax as
    > > Application_AuthenticateRequest as they are called on every request and
    > can
    > > be used to set the Principal.
    >
    > So, if you are not using cookies, what is the best way to maintain state
    > across a session? Do you set a session variable, say UserID, when the user
    > logs in, and get the user information from this in the Global.asax
    > Application_AuthenticateRequest each time to repopulate the context
    object?
    >
    > If you've gone this far with rolling your own solution, why bother with
    > setting the MS context authentication stuff on each Global.asax
    > Application_AuthenticateRequest, but instead just check the filepath using
    > HttpContext.Current.Server.MapPath() (or whatever else you need to
    configure
    > you authentication framework) and set roles and permissions accordingly in
    > your own framework (eg session variables)?
    >
    > It would not be too heavy (only involving two or three session variables,
    eg
    > userID, role, and permissions).
    >
    > What would be the pros and cons of this approach?
    >
    > MS have not made their forms authentication framework intuitive at all
    IMO.
    >
    > Lauchlan M
    >
    >

    Teemu Keiski Guest

  5. #4

    Default Re: lack of understanding of principals, identities, and context

    From a performance perspective, which is going to be more efficient -
    custom session variables, or recreating an authentication ticket on
    every Application_AuthenticateRequest?

    There is no other way to maintain a principal and identity without
    doing it every request, huh? Bummer.


    "Teemu Keiski" <joteke@NOSPAMaspalliance.com> wrote in message news:<#jqC#GyZDHA.1280@tk2msftngp13.phx.gbl>...
    > It really concerns things when authenticating and/or authorizing are hard
    > customized and it isn't just Forms Authentication specific. In simple case I
    > don't see anything wrong with simple session solution but framework support
    > is one main thing why I'd avoid it.
    >
    > Other thing when it is used would be when you use role-based authentication.
    > In that case you could let Forms Authentication to handle the authenticating
    > and store roles into the login cookie (UserData property of
    > FormsAuthenticationTicket). Then on Application_Authenticaterequest it is
    > checked if Request.IsAuthenticated=true (login cookie exists in case Forms
    > auth) and then roles read from cookie and again custom IPrincipal populated
    > with information regarding roles.
    >
    > In case when cookies are not allowed, you still can use Forms Authentication
    > (I think I have explained it to you earlier). In that case the
    > FormsAuthenticationTicket is persisted in the Querystring, but the drawback
    > was with keeping this on every page so that login information is persisted
    > when user navigates on the site. But if you want to avoid this drawback,
    > getting to use cookieless sessions is one solution and that leads to the
    > solution you discussed about.
    >
    > --
    > Teemu Keiski
    > MCP,Designer/Developer
    > Mansoft tietotekniikka Oy
    > [url]http://www.mansoft.fi[/url]
    >
    > AspInsiders Member, [url]www.aspinsiders.com[/url]
    > ASP.NET Forums Moderator, [url]www.asp.net[/url]
    > AspAlliance Columnist, [url]www.aspalliance.com[/url]
    >
    >
    > "Lauchlan M" <LMackinnon@Hotmail.com> kirjoitti viestissä
    > news:%23asS0TwZDHA.1280@tk2msftngp13.phx.gbl...
    > > > HttpContext is request specific (recreated for every request) and
    > therefore
    > > > you'd need to set the user on every request that means creating instance
    > of
    > > > FiveADayPrincipal and assigning it to the Context.User.
    > > >
    > > > Therefore there exists methods in Global.asax as
    > > > Application_AuthenticateRequest as they are called on every request and
    > can
    > > > be used to set the Principal.
    > >
    > > So, if you are not using cookies, what is the best way to maintain state
    > > across a session? Do you set a session variable, say UserID, when the user
    > > logs in, and get the user information from this in the Global.asax
    > > Application_AuthenticateRequest each time to repopulate the context
    > object?
    > >
    > > If you've gone this far with rolling your own solution, why bother with
    > > setting the MS context authentication stuff on each Global.asax
    > > Application_AuthenticateRequest, but instead just check the filepath using
    > > HttpContext.Current.Server.MapPath() (or whatever else you need to
    > configure
    > > you authentication framework) and set roles and permissions accordingly in
    > > your own framework (eg session variables)?
    > >
    > > It would not be too heavy (only involving two or three session variables,
    > eg
    > > userID, role, and permissions).
    > >
    > > What would be the pros and cons of this approach?
    > >
    > > MS have not made their forms authentication framework intuitive at all
    > IMO.
    > >
    > > Lauchlan M
    > >
    > >
    Bryan Ax Guest

  6. #5

    Default Re: lack of understanding of principals, identities, and context

    Hold on - one more thing...

    If I login a user, then create an identity object, then do this...

    FormsAuthentication.SetAuthCookie(myUserObject.Use rName, false);

    will that make it so they remain logged in, and I don't need to check
    and recreate it in Application_AuthenticateRequest? It appears so, but
    before I go too much further, I wanted to ask people smarter than me.


    [email]bax@kleinbuendel.com[/email] (Bryan Ax) wrote in message news:<7aa793c0.0308210639.344d496e@posting.google. com>...
    > From a performance perspective, which is going to be more efficient -
    > custom session variables, or recreating an authentication ticket on
    > every Application_AuthenticateRequest?
    >
    > There is no other way to maintain a principal and identity without
    > doing it every request, huh? Bummer.
    >
    >
    > "Teemu Keiski" <joteke@NOSPAMaspalliance.com> wrote in message news:<#jqC#GyZDHA.1280@tk2msftngp13.phx.gbl>...
    > > It really concerns things when authenticating and/or authorizing are hard
    > > customized and it isn't just Forms Authentication specific. In simple case I
    > > don't see anything wrong with simple session solution but framework support
    > > is one main thing why I'd avoid it.
    > >
    > > Other thing when it is used would be when you use role-based authentication.
    > > In that case you could let Forms Authentication to handle the authenticating
    > > and store roles into the login cookie (UserData property of
    > > FormsAuthenticationTicket). Then on Application_Authenticaterequest it is
    > > checked if Request.IsAuthenticated=true (login cookie exists in case Forms
    > > auth) and then roles read from cookie and again custom IPrincipal populated
    > > with information regarding roles.
    > >
    > > In case when cookies are not allowed, you still can use Forms Authentication
    > > (I think I have explained it to you earlier). In that case the
    > > FormsAuthenticationTicket is persisted in the Querystring, but the drawback
    > > was with keeping this on every page so that login information is persisted
    > > when user navigates on the site. But if you want to avoid this drawback,
    > > getting to use cookieless sessions is one solution and that leads to the
    > > solution you discussed about.
    > >
    > > --
    > > Teemu Keiski
    > > MCP,Designer/Developer
    > > Mansoft tietotekniikka Oy
    > > [url]http://www.mansoft.fi[/url]
    > >
    > > AspInsiders Member, [url]www.aspinsiders.com[/url]
    > > ASP.NET Forums Moderator, [url]www.asp.net[/url]
    > > AspAlliance Columnist, [url]www.aspalliance.com[/url]
    > >
    > >
    > > "Lauchlan M" <LMackinnon@Hotmail.com> kirjoitti viestissä
    > > news:%23asS0TwZDHA.1280@tk2msftngp13.phx.gbl...
    > > > > HttpContext is request specific (recreated for every request) and
    > therefore
    > > > > you'd need to set the user on every request that means creating instance
    > of
    > > > > FiveADayPrincipal and assigning it to the Context.User.
    > > > >
    > > > > Therefore there exists methods in Global.asax as
    > > > > Application_AuthenticateRequest as they are called on every request and
    > can
    > > > > be used to set the Principal.
    > > >
    > > > So, if you are not using cookies, what is the best way to maintain state
    > > > across a session? Do you set a session variable, say UserID, when the user
    > > > logs in, and get the user information from this in the Global.asax
    > > > Application_AuthenticateRequest each time to repopulate the context
    > object?
    > > >
    > > > If you've gone this far with rolling your own solution, why bother with
    > > > setting the MS context authentication stuff on each Global.asax
    > > > Application_AuthenticateRequest, but instead just check the filepath using
    > > > HttpContext.Current.Server.MapPath() (or whatever else you need to
    > configure
    > > > you authentication framework) and set roles and permissions accordingly in
    > > > your own framework (eg session variables)?
    > > >
    > > > It would not be too heavy (only involving two or three session variables,
    > eg
    > > > userID, role, and permissions).
    > > >
    > > > What would be the pros and cons of this approach?
    > > >
    > > > MS have not made their forms authentication framework intuitive at all
    > IMO.
    > > >
    > > > Lauchlan M
    > > >
    > > >
    Bryan Ax Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139