Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887

    [C# 4.0] Random identico con due tab

    Genero un Random (stringa) come Username nella maschera di creazione utente.

    Se apro due tab, me lo genera identico...in Produzione, sotto Load Balancing.
    Senza bilanciatore (in ambiente di Test) non lo fa.

    C'è un barbatrucco da web.config da settare ? (magari riguardo la Sessione -- o anche no ?)
    Ultima modifica di djciko; 27-04-2016 a 18:56

  2. #2
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    codice:
            public static String createUserLogin()
            {
                String NuovoUserName = "";
                String Caratteri = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
                Random randomNumber = new Random();
                Boolean user = false;
                String Query = "";
                SqlCommand selectCmd;
    
    
                using (SqlConnection cnn = new SqlConnection(DALFactory.DbConnectionString))
                {
                    try
                    {
                        cnn.Open(); // Open DB Connection using Connection Pool
    
    
                        while (!user)
                        {
                            for (Int32 i = 0; i < 8; i++)
                            {
                                Int32 rndNum = randomNumber.Next(1, 62);
                                NuovoUserName = NuovoUserName + Caratteri.Substring(rndNum, 1);
                            }
    
    
                            Query = "Select * from xxxxxxx WHERE USR_LOGIN='" + NuovoUserName + "'";
                            selectCmd = new SqlCommand(Query, cnn);
                            SqlDataReader reader = selectCmd.ExecuteReader();
                            if (!reader.HasRows) user = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        String retTemp = ex.Message;
                        //Return Error
                    }
                }
                return NuovoUserName;
            }

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.