FormsAuthentication Class Question

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

  1. #1

    Default FormsAuthentication Class Question

    First, here's a quick description of what I have so far. I have a website
    that I am building that contains both asp and asp.net pages. I have
    configured the site using a custom HTTPHandler, web.config, and a custom
    HTTPModule so that all requests (both asp and asp.net) go through the
    asp.net runtime. Asp requests are then redirected to the asp handler and
    asp.net are processed as normal. The entire site is then password protected
    using forms authentication and authorization to any page or sub app is
    controlled through the web.config in my root web. My custom HTTPModule
    handles the Authenticate Request event so that I can check my cookie, that I
    set on my login page, decrypt it and get my user and group info. All of
    this works perfectly on the asp.net side. I now want to be able to use that
    same cookie that I can access in my regular old asp pages decrypt it and get
    my user info. I made a class that uses the FormsAuthentication Class and
    thought I could decrypt my cookie that way. The problem I found was that
    the FormsAuthentication class only works when called within a asp.net
    application because when you call the Decrypt method it initializes which
    looks for the encryption keys in the web.config file. My custom class
    called from an asp page through interop obviously does not have this, so I
    get this error:

    System.NullReferenceException: Object reference not set to an instance of an
    object. at System.Web.Security.FormsAuthentication.Initialize () at
    System.Web.Security.FormsAuthentication.Decrypt(St ring encryptedTicket) at
    CustomHandlers.AuthenticationAccessor.SetAuthTicke t(String CookieValue)

    Does anyone have any ideas how I might be able to decrypt the cookie on the
    ASP side of things? Would not using the Encrypt method of the
    FormsAuthentication class on my login page and instead writing a custom
    encrypter be the best way to go?


    ==============
    Joe Reazor
    Gorbel Inc.
    email: joerea=AT=gorbel=DOT=com


    Joe Reazor Guest

  2. Similar Questions and Discussions

    1. Forms Auth and FormsAuthentication.SignOut()Question
      I'm using Form Auth. I 'm using the FormsAuthentication.SignOut() to sign out But when the user logins in and later logs out using...
    2. [:^class:] question
      Howdy, perldoc perlre on 5.8.0 says that should match any ascii character and is the negate version. If I do =~m// or on astring that is...
    3. ^class:] question
      > Howdy, Oops I meant ] or ] sorry ;p
    4. Question on the FormsAuthentication.Encrypt method
      I want to encrypt the values of my cookies. I found out that I could create a FormsAuthenticationTicket, and use the FormsAuthentication.Encrypt...
    5. [PHP] Class Design Question...
      anachronism@mengelt.com <mailto:anachronism@mengelt.com> on Wednesday, August 06, 2003 9:34 AM said: /Sounds/ like a good idea. Are you...
  3. #2

    Default RE: FormsAuthentication Class Question

    Hi Joe,

    I think you have to create customized encryption/decryption under this
    situation. For example, with CryptoStream in .NET. You may take a look at
    this article for this:

    Encrypting Data
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    l/cpconencryptingdata.asp

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    [MSFT] Guest

  4. #3

    Default Re: FormsAuthentication Class Question

    Thanks Luke, I was afraid that was going to be the answer. The thing that I
    am getting stuck on now is that if I don't use FormAuthentication.Encrypt
    and instead do the encrypt myself, I'm not sure what this Encrypt method
    does? You pass it an authentication ticket and it returns an encrypted
    version. How exactly do I reproduce that but with my own class?


    ==============
    Joe Reazor
    Gorbel Inc.
    email: joerea=AT=gorbel=DOT=com


    "[MSFT]" <lukezhan@online.microsoft.com> wrote in message
    news:0tbpYF5QEHA.304@cpmsftngxa10.phx.gbl...
    > Hi Joe,
    >
    > I think you have to create customized encryption/decryption under this
    > situation. For example, with CryptoStream in .NET. You may take a look at
    > this article for this:
    >
    > Encrypting Data
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > l/cpconencryptingdata.asp
    >
    > Luke
    > Microsoft Online Support
    >
    > Get Secure! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >

    Joe Reazor Guest

  5. #4

    Default Re: FormsAuthentication Class Question

    This is getting frustrating. In trying to implement a custom
    encryptor/decryptor using RijndaelManaged class I found out that I can't
    directly encrypt a FormsAuthenticationTicket when I am outside of a webforms
    application. The stack trace yielded the same issue I saw before where the
    call to FormsAuthentication.Initialize that happens somewhere in the .net
    runtime fails, I'm guessing because I'm outside of a forms app. Its
    annyoing though because I just want to use the ticket and its data. I guess
    I can ignore trying to return a ticket from my custom class and just provide
    access to the ticket's data that is stored in the encrpyted cookie.

    In just thinking about it some more. I probably could just as easy go back
    to using standard FormsAuthentication encryption of my ticket, let my custom
    httpmodule use that for the begin authentication event to confirm the user
    is authenticated and on the login page I just add some extra code to encrypt
    just my username field as a separate cookie. Then I can access this in a
    custom class that is called through interop by my asp page and return it the
    username. Then on the asp side I can write my code to use that username to
    get user data from my SQL tables.

    Does that seem to make more sense?


    ==============
    Joe Reazor
    Gorbel Inc.
    email: joerea=AT=gorbel=DOT=com


    "Joe Reazor" <joenospam@belgor.com> wrote in message
    news:OZDcQKOREHA.2404@TK2MSFTNGP09.phx.gbl...
    > Thanks Luke, I was afraid that was going to be the answer. The thing that
    I
    > am getting stuck on now is that if I don't use FormAuthentication.Encrypt
    > and instead do the encrypt myself, I'm not sure what this Encrypt method
    > does? You pass it an authentication ticket and it returns an encrypted
    > version. How exactly do I reproduce that but with my own class?
    >
    >
    > ==============
    > Joe Reazor
    > Gorbel Inc.
    > email: joerea=AT=gorbel=DOT=com
    >
    >
    > "[MSFT]" <lukezhan@online.microsoft.com> wrote in message
    > news:0tbpYF5QEHA.304@cpmsftngxa10.phx.gbl...
    > > Hi Joe,
    > >
    > > I think you have to create customized encryption/decryption under this
    > > situation. For example, with CryptoStream in .NET. You may take a look
    at
    > > this article for this:
    > >
    > > Encrypting Data
    > >
    >
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm[/url]
    > > l/cpconencryptingdata.asp
    > >
    > > Luke
    > > Microsoft Online Support
    > >
    > > Get Secure! [url]www.microsoft.com/security[/url]
    > > (This posting is provided "AS IS", with no warranties, and confers no
    > > rights.)
    > >
    >
    >

    Joe Reazor Guest

  6. #5

    Default Re: FormsAuthentication Class Question

    Hi Joe,

    I think it is a fgood idea to encrypt username field as a separate cookie.
    Only cookie can be shared between asp and asp.net, not with application or
    session variant.

    Another idea is to upgrade all your asp files to aspx. Normally, we only
    need to change the filename directly.

    Luke
    Microsoft Online Support

    Get Secure! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    [MSFT] Guest

  7. #6

    Default Re: FormsAuthentication Class Question

    Thanks Luke. This is the approach that I have ended up taking. It seems
    the easiest and most straightforward and when we switch everything over to
    all aspx pages then this extra cookie can just go away.


    ==============
    Joe Reazor
    Gorbel Inc.
    email: joerea=AT=gorbel=DOT=com

    "[MSFT]" <lukezhan@online.microsoft.com> wrote in message
    news:oC65B#sREHA.3804@cpmsftngxa10.phx.gbl...
    > Hi Joe,
    >
    > I think it is a fgood idea to encrypt username field as a separate cookie.
    > Only cookie can be shared between asp and asp.net, not with application or
    > session variant.
    >
    > Another idea is to upgrade all your asp files to aspx. Normally, we only
    > need to change the filename directly.
    >
    > Luke
    > Microsoft Online Support
    >
    > Get Secure! [url]www.microsoft.com/security[/url]
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >

    Joe Reazor 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