Thanks, jipsen, your tips were very useful and I've resolved my troubles.
My custom login has to work exactly as DNN login does, I just have to add some cookies when the user logs in and clear them when the user logs off. So I copied the core login and add some code lines. But I forgot to change the line which adds to the http context the AuthenticationType, so it was DNN and when the user tried to logoff the site tried to use the core logoff procedure!
The line I mentioned is this:
Dim eventArgs As UserAuthenticatedEventArgs = New UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "DNN")
changed:
Dim eventArgs As UserAuthenticatedEventArgs = New UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "_mycustomlogintype_")
Hope this could help someone else.
Thank you
Federica