protected void LinkBackAdmin_Click(object sender, EventArgs e) { try { objUtente.Read(" WHERE UTE_ID_UTENTE = " + Convert.ToInt32(Session["UTE_ID_UTENTE_LAST"].ToString())); Session["UTE_ID_UTENTE"] = objUtente.Ute_id_utente.ToString(); Session["UTE_COGNOME"] = objUtente.Ute_cognome.ToString(); Session["UTE_NOME"] = objUtente.Ute_nome.ToString(); Session["UTE_SIGLA"] = objUtente.Ute_sigla.ToString(); Session["CLI_ID_CLIENTE"] = objUtente.Cli_id_cliente.ToString(); Session["IMPERSONATE"] = "0"; Dictionary <string, int> dizionarioPermessi = objUtente.BuildPermissions(); Session["dizionarioPermessi"] = dizionarioPermessi; string strScript = @"<script type='text/javascript'> self.location.href='/Web/Home/mainpage.aspx'; </script>"; if (!Page.ClientScript.IsClientScriptBlockRegistered("Alert_JS")) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "Alert_JS", strScript); } } catch (Exception ex) { // Gestione messaggistica all'utente e trace in DB dell'errore if (!ex.Data.Contains("Class.Method")) { ex.Data.Add("Class.Method", "Web_frm_MSU_CDC.ButtonSalva_Click."); } ExceptionPolicy.HandleException(ex, "Propagate Policy"); } }
protected void Page_Load(object sender, EventArgs e) { Utente objUtente = new Utente(); //string userId = (Request.Form["STR_USERID"].ToString() != null)?Request.Form["STR_USERID"].ToString():"giorgio.belloni"; //Response.Write(userId); string userId = Request.Form["STR_USERID"].ToString(); if (userId.ToLower() != "admin") { objUtente.Read(" WHERE UTE_USER_ID = '" + userId.Replace("'", "''") + "'"); Session["UTE_ID_UTENTE"] = objUtente.Ute_id_utente.ToString(); Session["UTE_COGNOME"] = objUtente.Ute_cognome.ToString(); Session["UTE_NOME"] = objUtente.Ute_nome.ToString(); Session["UTE_SIGLA"] = objUtente.Ute_sigla.ToString(); Session["CLI_ID_CLIENTE"] = objUtente.Cli_id_cliente.ToString(); Session["NAZ_ID_NAZIONE"] = 1; Session["CULTURE_INFO_NAME"] = "it"; Session["RIV_ID_RICHIESTA"] = 0; objUtente.UltimoAccesso(); Dictionary <string, int> dizionarioPermessi = objUtente.BuildPermissions(); Session["dizionarioPermessi"] = dizionarioPermessi; //Faccio l'autenticazione senza fare il login FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version userId, // user name DateTime.Now, // creation DateTime.Now.AddHours(10), // Expiration false, // Persistent ""); // User data // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies Response.Cookies.Add(authCookie); //Fine autenticazione Response.Redirect("../HOME/mainpage.aspx", false); } }
/// <summary> /// Alla conferma recupero le informazioni dell'utente impersonato e rimando l'utente alla Dashboard. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnImpersonaUtente_Click(object sender, EventArgs e) { try { //Memorizzo in questa sessione l'id dell'utente che sta eseguendo l'impersonate Session["UTE_ID_UTENTE_LAST"] = Session["UTE_ID_UTENTE"]; //Ricavo i dati per l'impersonificazione objUtente.Read(" WHERE UTE_ID_UTENTE = " + txtUtente.SelectedValue); Session["UTE_ID_UTENTE"] = objUtente.Ute_id_utente.ToString(); Session["UTE_COGNOME"] = objUtente.Ute_cognome.ToString(); Session["UTE_NOME"] = objUtente.Ute_nome.ToString(); Session["UTE_SIGLA"] = objUtente.Ute_sigla.ToString(); Session["CLI_ID_CLIENTE"] = objUtente.Cli_id_cliente.ToString(); Session["IS_GESTIONE_GRUPPO"] = objUtente.Ute_gestione_gruppo.Value; Session["IMPERSONATE"] = "1"; Dictionary <string, int> dizionarioPermessi = objUtente.BuildPermissions(); Session["dizionarioPermessi"] = dizionarioPermessi; string strScript = @"<script type='text/javascript'> // self.parent.location.reload(); document.location.href='../Home/mainpage.aspx'; </script>"; if (!this.ClientScript.IsStartupScriptRegistered("Alert_JS")) { this.ClientScript.RegisterStartupScript(GetType(), "Alert_JS", strScript); } } catch (Exception ex) { // Gestione messaggistica all'utente e trace in DB dell'errore if (!ex.Data.Contains("Class.Method")) { ex.Data.Add("Class.Method", "Web_frm_MSE_IMP.ButtonSalva_Click."); } ExceptionPolicy.HandleException(ex, "Propagate Policy"); } }
protected void ButtonLogin_Click(object sender, EventArgs e) { Utente objUtente = new Utente(); Audit objAudit = new Audit(); int naz_id_nazione; bool passwordVerified = false; bool macAddressVerified = false; string pagina = string.Empty; int nroMaxSessioni = 0; int nroSessioniAttive = 0; //Ricavo informazioni sul browser dell'utente che si collega. vInfoBrowser = "Impostazioni Browser" + Environment.NewLine + "Type = " + Request.Browser.Type + Environment.NewLine + "Name = " + Request.Browser.Browser + Environment.NewLine + "Version = " + Request.Browser.Version + Environment.NewLine + "Major Version = " + Request.Browser.MajorVersion + Environment.NewLine + "Minor Version = " + Request.Browser.MinorVersion + Environment.NewLine + "Platform = " + Request.Browser.Platform + Environment.NewLine + "Is Beta = " + Request.Browser.Beta + Environment.NewLine + "Is Crawler = " + Request.Browser.Crawler + Environment.NewLine + "Is AOL = " + Request.Browser.AOL + Environment.NewLine + "Is Win32 = " + Request.Browser.Win32 + Environment.NewLine + "Supports Frames = " + Request.Browser.Frames + Environment.NewLine + "Supports Tables = " + Request.Browser.Tables + Environment.NewLine + "Supports Cookies = " + Request.Browser.Cookies + Environment.NewLine + "Supports VBScript = " + Request.Browser.VBScript + Environment.NewLine + "Supports JavaScript = " + Request.Browser.EcmaScriptVersion.ToString() + Environment.NewLine + "Supports Java Applets = " + Request.Browser.JavaApplets + Environment.NewLine + "Supports ActiveX Controls = " + Request.Browser.ActiveXControls + Environment.NewLine + "Supports Callback = " + Request.Browser.SupportsCallback + Environment.NewLine + "User Agent = " + HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].ToString().ToLower(); divLoginMessage.Visible = false; strERRORE = ""; try { objUtente.Ute_user_id = InputUser.Text; objUtente.Ute_password = EncryptPwd(InputPassword.Text); if (!IsPostBack) { objUtente.Ute_user_id = autoLoginId; passwordVerified = objUtente.CheckLogin(false); if (passwordVerified) { autoLoginKerberosVerified = true; } } else { passwordVerified = objUtente.CheckLogin(true); //objUtente-> in Utente.cs } //Ricavo il nro massimo delle sessioni disponibili per l'utente corrente //e il nro di sessioni effettivamente attive per l'utente corrente if (passwordVerified) { nroMaxSessioni = objUtente.Ute_nro_max_sessioni.Value; nroSessioniAttive = objSessioniUtenti.CountSessioni(objUtente.Ute_id_utente.Value); } else { //Messi dei valori di comodo per farlo entrare nel successivo IF della password errata. nroMaxSessioni = 1; nroSessioniAttive = 0; } //******************************************************************************** // Commentare DA QUI per creare dll che non controlla il mac address //******************************************************************************** /* * byte[] defaultParameters = { 99, 99, 99 }; * JsonTextReader readerMacAddress = MacAddress.GetArrayMacAddress(); * Utilita objUtilita = new Utilita(); * byte[] microsoftAdvertisingClass = objUtilita.getMicrosoftAdvertisingClass(); * string macAddressCheck = string.Empty; * * while (readerMacAddress.Read() && passwordVerified) * { * if (readerMacAddress.TokenType.ToString() == "String" && !macAddressVerified) * { * defaultParameters = Encoding.ASCII.GetBytes(readerMacAddress.Value.ToString()); * int z = 0; * foreach (string val in readerMacAddress.Value.ToString().Split(',')) * { * defaultParameters[z] = Convert.ToByte(val); * z++; * } * //logger.Log(" -> defaultParameters -> " + readerMacAddress.Value.ToString()); * int i = 0; * int countCheck = 0; * foreach (byte b in microsoftAdvertisingClass) * { * macAddressCheck += b + ","; * if (b == defaultParameters[i]) * { * //logger.Log(" -> mcAddressVerified -> true"); * countCheck++; * if (countCheck == 15) * { * macAddressVerified = true; * break; * } * } * else * { * //logger.Log(" -> mcAddressVerified -> false -> bity:" + b.ToString() + " defaultParameters["+i.ToString()+"]-> " + defaultParameters[i].ToString()); * macAddressVerified = false; * } * i++; * } * } * } */ //******************************************************************************** // Commentare FIN QUI per creare dll che non controlla il mac address //******************************************************************************** Session["RIV_ID_RICHIESTA"] = 0; //******************************************************************************** if (nroSessioniAttive >= nroMaxSessioni) { errMessage = GetValueDizionarioUI("ERR_MSG_MAX_SESSIONI_ATTIVE"); LabelMessage.InnerText = errMessage; LabelMessage.Style.Add("color", "red"); divLoginMessage.Visible = true; } else if (passwordVerified) { Session["UTE_ID_UTENTE"] = objUtente.Ute_id_utente.Value; Session["UTE_SIGLA"] = (objUtente.Ute_sigla.IsNull) ? (string.Empty) : (objUtente.Ute_sigla.Value); Session["IP_ADDRESS"] = Convert.ToString(Request.ServerVariables["REMOTE_ADDR"]); Session["UTE_COGNOME"] = objUtente.Ute_cognome.Value; Session["UTE_NOME"] = objUtente.Ute_nome.Value; Session["CLI_ID_CLIENTE"] = objUtente.Cli_id_cliente.Value; Session["IS_GESTIONE_GRUPPO"] = objUtente.Ute_gestione_gruppo.Value; if (objUtente.Tpi_acronimo.Value != "") { Session["ACRONIMO_INSTALLAZIONE"] = objUtente.Tpi_acronimo.Value; } else { Session["ACRONIMO_INSTALLAZIONE"] = ""; } Response.Write(Session["UTE_ID_UTENTE"].ToString()); try { objAudit.Ute_id_utente = objUtente.Ute_id_utente; objAudit.Aud_ip_address = Convert.ToString(Session["IP_ADDRESS"]); objAudit.Aud_device = vInfoBrowser; //HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].ToString().ToLower(); objAudit.TraceAction("Login"); Session["AUD_ID_AUDIT"] = objAudit.Aud_id_audit; Dictionary <string, int> dizionarioPermessi = objUtente.BuildPermissions(); Session["dizionarioPermessi"] = dizionarioPermessi; // Create the authentication ticket FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version InputUser.Text, // user name DateTime.Now, // creation DateTime.Now.AddHours(10), // Expiration false, // Persistent ""); // User data // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies Response.Cookies.Add(authCookie); if (hLingua.SelectedValue != "") { naz_id_nazione = Convert.ToInt32(hLingua.SelectedValue); } else { naz_id_nazione = idLingua; } Session["NAZ_ID_NAZIONE"] = naz_id_nazione; // La Culture Info deve sempre essere IT in quanto non devo cambiare formato di date e numeri Session["CULTURE_INFO_NAME"] = "it"; Session["SIGLA_LINGUA"] = hSiglaLingua.Value; setSessionId(); //Faccio la read del cliente per acronimo del cliente per andare alle richieste viaggio corrispondenti objClienti.Read(objUtente.Cli_id_cliente, qCultureInfoName); pagina = "../HOME/mainpage.aspx"; if (objUtente.Ute_id_utente != 1) // Admin { pagina = "../RichiestaViaggio_" + objClienti.Cli_acronimo.Value + "/frm_MSB_RIV.aspx?MENU=1"; } if (objSistema.Sis_flag_pwd_cambia_primo_accesso == 1 && objUtente.Ute_ultimo_accesso.IsNull) { //Ogni login è l'ultimo Accesso Utente objUtente.UltimoAccesso(); objUtente.Login_Logout("Login"); Response.Redirect("../LOGIN/frm_PWD.aspx?SCADUTA=SI", false); } else if (objSistema.Sis_flag_pwd_cambia == 1) { if (objUtente.Ute_expiration_date.IsNull) { if (objSistema.Sis_flag_visualizza_info_page == 1) { Response.Redirect("frm_LGN_2.aspx", false); } else { //Ogni login è l'ultimo Accesso Utente objUtente.UltimoAccesso(); Response.Redirect(pagina, false); } } else if (Convert.ToDateTime(objUtente.Ute_expiration_date.Value) < Convert.ToDateTime(DateTime.Now.ToShortDateString())) { //Ogni login è l'ultimo Accesso Utente objUtente.UltimoAccesso(); objUtente.Login_Logout("Login"); Response.Redirect("../LOGIN/frm_PWD.aspx?SCADUTA=SI", false); } else { if (objSistema.Sis_flag_visualizza_info_page == 1) { Response.Redirect("frm_LGN_2.aspx", false); } else { //Ogni login è l'ultimo Accesso Utente objUtente.UltimoAccesso(); objUtente.Login_Logout("Login"); Response.Redirect(pagina, false); } } } else { if (objSistema.Sis_flag_visualizza_info_page == 1) { Response.Redirect("frm_LGN_2.aspx", false); } else { //Ogni login è l'ultimo Accesso Utente objUtente.UltimoAccesso(); objUtente.Login_Logout("Login"); Response.Redirect(pagina, false); } } } catch (Exception ex) { strERRORE = ex.Message; ExceptionPolicy.HandleException(ex, "Propagate Policy"); Response.Redirect("../Login/frm_LGN.aspx", false); } } else { if (!autoLoginKerberosVerified) { divLoginMessage.Visible = true; LabelMessage.InnerText = "Utente non presente nel sistema di autenticazione."; LabelMessage.Style.Add("color", "red"); InputUser.Text = autoLoginId; } else if (!passwordVerified) { divLoginMessage.Visible = true; LabelMessage.InnerText = "Password non valida."; LabelMessage.Style.Add("color", "red"); if (objSistema.Sis_max_tentativi_password != -1) { objUtente.Ute_user_id = InputUser.Text; if (objUtente.AccessoErrato() == 1) { objUtente.SqlWhereClause = " WHERE UTE_USER_ID = '" + InputUser.Text + "' "; objUtente.DisattivaUserID(); LabelMessage.InnerHtml = errDisabledUser; LabelMessage.Style.Add("color", "red"); } } } else if (!macAddressVerified) { divLoginMessage.Visible = true; LabelMessage.InnerText = "Mac Address non valido. Contattare l'amministratore di sistema."; // + macAddressCheck; LabelMessage.Style.Add("color", "red"); } else { if (objUtente.CheckUser()) { objAudit.Ute_id_utente = objUtente.Ute_id_utente; objAudit.Aud_ip_address = Convert.ToString(Session["IP_ADDRESS"]); objAudit.TraceAction("LoginFailed"); } LabelMessage.InnerText = errMessage; LabelMessage.Style.Add("color", "red"); divLoginMessage.Visible = true; strERRORE = errMessage; } } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, "Propagate Policy"); } }
//E' presente anche nella Default.aspx //public bool IsMobile() //{ // bool retValue = false; // try //try , because sometimes user agent is empty // { // string ua = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].ToString().ToLower(); // string[] uaArray = { "android", "maui", "ppc", "opera mobi", "symbian", "series", "nokia", "mot-", "motorola", "lg-", "lge", "nec-", "lg/", "samsung", "sie-", "sec-", "sgh-", "sonyericsson", "sharp", "windows ce", "portalmmm", "o2-", "docomo", "philips", "panasonic", "sagem", "smartphone", "up.browser", "up.link", "googlebot-mobile", "googlebot-image", "slurp", "spring", "alcatel", "sendo", "blackberry", "opera mini", "opera 2", "netfront", "mobilephone mm", "vodafone", "avantgo", "palmsource", "siemens", "toshiba", "i-mobile", "asus", "kwc", "htc", "softbank", "playstation", "nitro", "ipod", "google wireless transcoder", "t-mobile", "obigo", "brew" }; //"ice", // bool foundInArray = false; // foreach (string s in uaArray) // { // if (ua.IndexOf(s) > -1) // { // foundInArray = true; // break; // } // } // if (foundInArray == true || HttpContext.Current.Request.Browser.IsMobileDevice || HttpContext.Current.Request.ServerVariables["HTTP_ACCEPT"].Contains("application/vnd.wap.xhtml+xml")) // retValue = true; // } // catch (Exception e) // { // string foo = e.Message; // } // return retValue; //} void ByPassLogin(string idMailClick) { string idRichiesta = string.Empty; string wrfCodice = string.Empty; bool loginVerified = false; Audit objAudit = new Audit(); Utente objUtente = new Utente(); objUtente.Mac_codice_univoco = idMailClick; loginVerified = objUtente.CheckByPassLogin(); idRichiesta = objUtente.Riv_id_richiesta.ToString(); wrfCodice = objUtente.Ioa_wrf_codice.ToString(); //Pensare di centralizzare questo controllo. Session["UTE_ID_UTENTE"] = objUtente.Ute_id_utente.Value; Session["UTE_SIGLA"] = (objUtente.Ute_sigla.IsNull) ? (string.Empty) : (objUtente.Ute_sigla.Value); Session["IP_ADDRESS"] = Convert.ToString(Request.ServerVariables["REMOTE_ADDR"]); Session["UTE_COGNOME"] = objUtente.Ute_cognome.Value; Session["UTE_NOME"] = objUtente.Ute_nome.Value; Session["CLI_ID_CLIENTE"] = objUtente.Cli_id_cliente.Value; if (objUtente.Tpi_acronimo.Value != "") { Session["ACRONIMO_INSTALLAZIONE"] = objUtente.Tpi_acronimo.Value; } else { Session["ACRONIMO_INSTALLAZIONE"] = ""; } Response.Write(Session["UTE_ID_UTENTE"].ToString()); try { objAudit.Ute_id_utente = objUtente.Ute_id_utente; objAudit.Aud_ip_address = Convert.ToString(Session["IP_ADDRESS"]); objAudit.TraceAction("Login"); Session["AUD_ID_AUDIT"] = objAudit.Aud_id_audit; Dictionary <string, int> dizionarioPermessi = objUtente.BuildPermissions(); Session["dizionarioPermessi"] = dizionarioPermessi; // Create the authentication ticket FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version InputUser.Text, // user name DateTime.Now, // creation DateTime.Now.AddHours(10), // Expiration false, // Persistent ""); // User data // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies Response.Cookies.Add(authCookie); int naz_id_nazione = 1;//Convert.ToInt32(RadioButtonLingua.SelectedItem.Value); Session["NAZ_ID_NAZIONE"] = naz_id_nazione; Session["CULTURE_INFO_NAME"] = "it"; //SVA(07102011): Una volta che mi loggo inserisco nella tabella delle Sessioni le informazioni //relative all'utente che si è loggato. setSessionId(); } catch (Exception ex) { // Gestione messaggistica all'utente e trace in DB dell'errore ExceptionPolicy.HandleException(ex, "Propagate Policy"); } //***************************************** if (idRichiesta != null) { Response.Redirect("../HOME/mainpage.aspx?ID_RICHIESTA=" + idRichiesta + "&CODICE_WORKFLOW=" + wrfCodice, false); } }