When exactly are you logged in? (Forms authentication)

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

  1. #1

    Default When exactly are you logged in? (Forms authentication)

    Hi.

    For forms authentication, the standard way to go would be something like

    <<

    1. Get user name and password

    2. Look it up against database store

    3. Create an authentication ticket

    4. Create an authentication cookie (based on the ticket)

    5. Redirect as required/appropriate

    6. In the Global_AuthenticateRequest event handler, code it something like:

    <<

    // private void Global_AuthenticateRequest(object sender, System.EventArgs
    e)

    // (if authentication ticket is recovered from a cookie or session
    variable then:)

    // pipe delimited string of role names.
    string[] roles = authTicket.UserData.Split(new char[]{'|'});

    // Create an Identity object
    FormsIdentity id = new FormsIdentity( authTicket );

    // This principal will flow throughout the request.
    GenericPrincipal principal = new GenericPrincipal(id, roles);

    // Attach the new principal object to the current HttpContext object
    Context.User = principal;

    // (else bounce them back to the login page)
    >>
    >>
    Now, I don't want to use cookies (ie operate cookieless). If I created an
    authentication ticket in my login.aspx, encrypted it (ie to a string) and
    put it in a session variable and caught this session variable, decrypted it
    and recreated the Context.user principal in in the
    Global_AuthenticateRequest handler, would it be logged in at that point
    (regardless of the fact that I never created any cookie)?

    Thanks!

    Lauchlan M


    Lauchlan M Guest

  2. Similar Questions and Discussions

    1. Accessing htm files without authentication (forms authentication)
      I have application with forms authentication. All works fine. When user opens .aspx file gets login form, login and then get the .aspx page. But...
    2. ASP.Net Forms authentication with basic authentication popup
      Relatively new to ASP.Net but have a strange problem. My site uses forms authentication for a large administration section however after the user...
    3. Forms authentication then redirection to a secure web with NT authentication?
      Hi, I want to allow access to particular secured intranet web sites. These intranet are stored in sharepoint (2003 version) Actually I've...
    4. Authentication ticket, cookieless, forms authentication?
      Hi. I want to use Forms Authentication, cookieless. The issue is setting the Authentication Ticket without using cookies (!) That is, the...
    5. Username not logged in IIS when using forms authentication with Active Directory
      Hi! I've succesfully implemented Forms Authentication with a Active Directory, described at...
  3. #2

    Default When exactly are you logged in? (Forms authentication)

    You can't use FormsAuthentication without cookie.
    What you can do is to create your own Authentication
    module, read this site:

    [url]http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%[/url]
    3B318786

    /Fredrik Normén NSQUARED2
    [url]http://www.nsquared2.net[/url]

    >-----Original Message-----
    >Hi.
    >
    >For forms authentication, the standard way to go would
    be something like
    >
    ><<
    >
    >1. Get user name and password
    >
    >2. Look it up against database store
    >
    >3. Create an authentication ticket
    >
    >4. Create an authentication cookie (based on the ticket)
    >
    >5. Redirect as required/appropriate
    >
    >6. In the Global_AuthenticateRequest event handler, code
    it something like:
    >
    ><<
    >
    > // private void Global_AuthenticateRequest(object
    sender, System.EventArgs
    >e)
    >
    > // (if authentication ticket is recovered from a
    cookie or session
    >variable then:)
    >
    > // pipe delimited string of role names.
    > string[] roles = authTicket.UserData.Split(new char[]
    {'|'});
    >
    > // Create an Identity object
    > FormsIdentity id = new FormsIdentity( authTicket );
    >
    > // This principal will flow throughout the request.
    > GenericPrincipal principal = new GenericPrincipal
    (id, roles);
    >
    > // Attach the new principal object to the current
    HttpContext object
    > Context.User = principal;
    >
    > // (else bounce them back to the login page)
    >
    >>>
    >
    >>>
    >
    >Now, I don't want to use cookies (ie operate
    cookieless). If I created an
    >authentication ticket in my login.aspx, encrypted it (ie
    to a string) and
    >put it in a session variable and caught this session
    variable, decrypted it
    >and recreated the Context.user principal in in the
    >Global_AuthenticateRequest handler, would it be logged
    in at that point
    >(regardless of the fact that I never created any cookie)?
    >
    >Thanks!
    >
    >Lauchlan M
    >
    >
    >.
    >
    Fredrik Normén NSQUARED2 Guest

  4. #3

    Default Re: When exactly are you logged in? (Forms authentication)

    Hi,

    thanks for the response.
    > You can't use FormsAuthentication without cookie.
    Well, how feeble is that?

    Actually, I think you can, eg using the mobile internet stuff

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mwsdk/html/mwconauthenticationoptionsformobiledevices.asp[/url]
    and
    [url]http://support.microsoft.com/default.aspx?scid=kb;%5bLN%5d;Q311568[/url]

    It's just that it's not easy, convenient, or a path I want to spend time
    pursuing. For example, using the MobileFormsAuthentication instead of
    FormsAuthentication doesn't let you just redirect with the authentication
    ticket cookie taken care of (passed in the url query string), this is only
    done when using RedirectFromLoginPage.
    > What you can do is to create your own Authentication
    > module, read this site:
    > [url]http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B318786[/url]
    Thanks for this. I've looked over it and it looks like too much overhead
    getitng my head around another overly-complicated MS approach as a hack for
    getting around their poorly thought out (in this regard) framework. But if
    you have a link on the philosophy/idea behind this so I can make more sense
    of this, I'll put it back in the list of options . . .

    It's reached the point where I've spent too much time trying to fit in to
    MS's authorisation schema, and just need to move ahead.

    So I figure I'll try:

    <<
    (i) blowing away the web.config authorisation and authentication elements

    (ii) In my login.aspx page, creating an "authenticated" session variable,
    and checking for it in the global.asax "Global_AcquireRequestState" handler
    and bouncing people back to Login.aspx if it's not there or not valid

    (iii) when logging in in login.aspx, create another session variable for
    userrole, and in the Global_AcquireRequestState handler, check the path
    explicitly for secure directory names (eg "private", "admin" or whatever I
    call them and check these manually against the relevant permissions defined
    by the roles and bounce them if they dont meet the criteria.

    At least I'll then implement the security I want, even if I can't manage to
    do it Microsoft's way. The 'cost' would be two session variables per user -
    "authenticated" and "role".
    >>
    If you see any problems with this approach, please let me know . . .

    Lauchlan M


    Lauchlan M 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