Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di 7vite
    Registrato dal
    Mar 2001
    Messaggi
    3,407

    [VB.NET] Leggere e settare un cookie

    Problema.

    Devo leggere un cookie all'accesso in una pagina aspx (sulla Page_Load).

    codice:
    if (questo cookie è nullo) then
    	assegnagli un valore 
    else
    	response.redirect ...
    end if
    Qual è il codice?

    (Ne ho trovati a bizzeffe ma nessuno funzionante ... non è che devo impostare anche qualcosa nel webconfig?)

    Grazie, 7#

  2. #2
    7vite, come va?
    prova una roba di questo genere

    codice:
    sub Page_Load
    		dim authcookie as HttpCookie
      		dim Ticket as FormsAuthenticationTicket
    		try
    			authcookie = Request.Cookies( FormsAuthentication.FormsCookieName )
    			Ticket = CType( FormsAuthentication.Decrypt( authcookie.Value ), FormsAuthenticationTicket )
    			response.Redirect( "pagina.aspx" )
    		catch
    			Ticket = new FormsAuthenticationTicket( 1, "valore", DateTime.Now, DateTime.Now, "false", 1 )
    			dim encTicket as string = FormsAuthentication.Encrypt( Ticket )
    			authCookie = New HttpCookie( FormsAuthentication.FormsCookieName, encTicket )
    			Response.Cookies.Add( authCookie )
    			response.Redirect( "pagina.aspx" )
    		end try
    	end sub
    "...non è detto che sia tardi se non guardi che ora è..."

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.