Greetings
In my portal while the user interacts with various pages, the system suddenly logs him out, whithout him pressing logout...
This behaviour is very strange since I havent altered any other code except the Login and Logout event handlers of DNN authentication services. The only thing I added is an extra check to another database to authenticate the user that tries to login to the portal... I simply put a cookie without using any standard authentication method. Anyway the only assumption I can make is that the authentication cookie of DNN somehow expires, but I dont think this is because of my extra check... I add my code at the end of the message...
Has anyone had the same problem before (with or without code changes)? Or can anyone assume why this sudden logout happens?
Thanks in advance
Private Sub cmdLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdLogin.Click
If (UseCaptcha And ctlCaptcha.IsValid) OrElse (Not UseCaptcha) Then
Dim loginStatus As UserLoginStatus = UserLoginStatus.LOGIN_FAILURE
Dim objUser As UserInfo = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, "DNN", txtVerification.Text, PortalSettings.PortalName, IPAddress, loginStatus)
Dim authenticated As Boolean = Null.NullBoolean
Dim message As String = Null.NullString
If loginStatus = UserLoginStatus.LOGIN_USERNOTAPPROVED Then
'Check if its the first time logging in to a verified site
If PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
If Not rowVerification1.Visible Then
'Display Verification Rows so User can enter verification code
rowVerification1.Visible = True
rowVerification2.Visible = True
message = "EnterCode"
Else
If txtVerification.Text <> "" Then
message = "InvalidCode"
Else
message = "EnterCode"
End If
End If
Else
message = "UserNotAuthorized"
End If
Else
authenticated = (loginStatus <> UserLoginStatus.LOGIN_FAILURE)
End If
Dim eventArgs As UserAuthenticatedEventArgs = New UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "DNN")
eventArgs.Authenticated = authenticated
eventArgs.Message = message
'EXTRA CODE GOES HERE
Dim userID As Long = -1
If authenticated Then
Try
userID = 'Connect to another database, authenticate the user and get his id
If (userExists) Then
If (Request.Cookies("isAuthenticated") Is Nothing) Then
Dim cookie = New HttpCookie("isAuthenticated")
cookie.Value = userID
Response.Cookies.Add(cookie)
End If
Else
eventArgs.LoginStatus = UserLoginStatus.LOGIN_FAILURE
eventArgs.Authenticated = False
End If
Catch ex As Exception
eventArgs.LoginStatus = UserLoginStatus.LOGIN_FAILURE
eventArgs.Authenticated = False
End Try
End If
'Raise UserAuthenticated Event
OnUserAuthenticated(eventArgs)
End If
End Sub
Private Sub Logoff()
If (Not Request.Cookies("isAuthenticated") Is Nothing) Then
Dim cookie = Request.Cookies("isAuthenticated")
cookie.Expires = DateTime.Now.AddDays(-1D)
Response.Cookies.Add(cookie)
End If
Try
'Remove user from cache
If Me.User IsNot Nothing Then
DataCache.ClearUserCache(Me.PortalSettings.PortalId, Context.User.Identity.Name)
End If
Dim objPortalSecurity As New PortalSecurity
objPortalSecurity.SignOut()
Catch exc As Exception 'Page failed to load
ProcessPageLoadException(exc)
End Try
End Sub