salvea tutti
ho questo codice per l'autenticazione:
codice:
FormsAuthentication.SetAuthCookie(Me.txtUser.Text, True)
''-------------------Profilo---------------------
Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
Me.txtUser.Text, _
DateTime.Now, _
DateTime.Now.AddMinutes(30), _
True, _
GetRuoloUser(Session("ID_Utente")).ToString, _
FormsAuthentication.FormsCookiePath)
Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName, encTicket))
Dim Ruolo As String = GetRuoloUser(Session("ID_Utente")).ToString
Dim Roles(9) As String
Roles(0) = GetRuoloUser(Session("ID_Utente"))(0) ' Data.GetUserRoles(User.Identity.Name)
Dim ID As FormsIdentity = CType(HttpContext.Current.User.Identity, FormsIdentity)
HttpContext.Current.User = New System.Security.Principal.GenericPrincipal(ID, Roles)
ovviamente nel web.config l'autenticazione è di tipo FORM
il problema è che al primo login mi da problema"Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Security.FormsIdentity'" proprio nella riga " Dim ID As FormsIdentity = CType(HttpContext.Current.User.Identity, FormsIdentity)
" da cosa puo' dipendere?
se dopo aver dato errore ,riprovo a riloggarmi, va tutto bene e la riga di codice me la passa senzxa problemi.