locked
Identity.IsAuthenticated always FALSE

    Question

  • Hi ,

     

    I get some problems with my authentication code. When the user enters my asp.net 2.0 website the first time,

    I want to check that a cookie is present on his disk, make a check via a stored proc in a sql server 2005 dbb

    then I'd like him to be authenticated without any more check during the whole session.

    My global.asax looks like that :

     

    public void FormsAuthentication_OnAuthenticate(object sender, FormsAuthenticationEventArgs args)

    {

    if ( ! Thread.CurrentPrincipal.Identity.IsAuthenticated )

    {

    //all my code to check that this user should access my web site

     

    Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(currentUser.ID.ToString()), currentUser.Roles);

     

    //here Thread.CurrentPrincipal.Identity.IsAuthenticated is actually set to true but for some reason

    //I can't understand this value set to true is not kept along the session

    }

     

    }

     

    Unfortunately my test Thread.CurrentPrincipal.Identity.IsAuthenticated always returns false

    so the whole check is done many times during one single session.

     

     

    Here is my web.config regarding authentication :

     

    <authentication mode="Forms">

    <forms loginUrl="/form/Verifid.asp" name="Login"></forms>

    </authentication>

     

    Note that the login is done on an asp page so not in the dotnet project.

    Should that work...?

     

     

    Any idea about what can be wrong?

     

    I can't find detailed documentation about Thread.CurrentPrincipal.Identity.IsAuthenticated ...: how is this property set to true, which is the link to GenericPrincipal et GenericIdentity, I'm a bit lost with what I could read about the subject... all explanation would be warmly welcome...

    Beside this does "FormsAuthentication" correctly work while authentication is done on an asp page "external" to the dotnet project ....

     

     

     

    Thanks for your help,

     

    idel 

     

    Tuesday, August 28, 2007 3:03 PM