public void PersistSessionTest() { // création des objets réponses Request et Response pour le HtppContext HttpRequest request = new HttpRequest("myFileName", "http://urlQuelconque", "BBQ=OUI"); Encoding requestEncoding = Encoding.GetEncoding("ISO-8859-1"); request.ContentEncoding = requestEncoding; // generate cookie AspSessionPersistence persist = new AspSessionPersistence(); string key = persist.GenerateSessionId(); HttpCookie cookie = new HttpCookie(AppSettingsManager.CookieName); cookie.Values.Add(AppSettingsManager.CookieKey, key); request.Cookies.Add(cookie); Stream str = Stream.Null; StreamWriter sw = new StreamWriter(str); HttpResponse response = new HttpResponse(sw); HttpContext context = new HttpContext(request, response); // Create AspSession AspSessionPersistenceTest pt = new AspSessionPersistenceTest(); AspSession asp_session = new AspSession(context); pt.CreateSessionState(asp_session.Contents); asp_session.PersistSession(); var sessloaded = persist.LoadSession(key); foreach (var item in asp_session.Contents) { Assert.AreEqual(item.Value, sessloaded[item.Key]); } }
protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e) { if (Session["user"] != null && Session["logok"] != null) { e.Authenticated = true; AspSession.Set("user", Session["user"].ToString()); AspSession.Set("username", Session["username"].ToString()); AspSession.Set("logok", Session["logok"].ToString()); lblErrorMsg.Text = "Access granted"; } else { e.Authenticated = false; } }
public void InitializeSessionTest() { // création des objets réponses Request et Response pour le HtppContext HttpRequest request = new HttpRequest("myFileName", "http://urlQuelconque", "BBQ=OUI"); Encoding requestEncoding = Encoding.GetEncoding("ISO-8859-1"); request.ContentEncoding = requestEncoding; Stream str = Stream.Null; StreamWriter sw = new StreamWriter(str); HttpResponse response = new HttpResponse(sw); HttpContext context = new HttpContext(request, response); AspSession asp_session = new AspSession(context); ReflectionUtility.CallNonPublicMethod(asp_session, "InitializeSession", null); // equivaut à asp_session.InitializeSession(); Assert.IsNotNull(asp_session.Contents); }
public void CreateNewSessionCookieTest() { // création des objets réponses Request et Response pour le HtppContext HttpRequest request = new HttpRequest("myFileName", "http://urlQuelconque", "BBQ=OUI"); Encoding requestEncoding = Encoding.GetEncoding("ISO-8859-1"); request.ContentEncoding = requestEncoding; Stream str = Stream.Null; StreamWriter sw = new StreamWriter(str); HttpResponse response = new HttpResponse(sw); HttpContext context = new HttpContext(request, response); var asp_session = new AspSession(context); string session_id = Guid.NewGuid().ToString().Replace("-", string.Empty); ReflectionUtility.SetNonPublicField(asp_session, "sessionId", session_id); HttpCookie cookie = (HttpCookie)ReflectionUtility.CallNonPublicMethod(asp_session, "SetSessionCookie", null); Assert.IsNotNull(cookie); var session_id_cookie_str = cookie["SessionId"]; Assert.AreEqual(session_id, session_id_cookie_str); }
protected StringBuilder crearMenu() { StringBuilder htmlTabla = new StringBuilder(); string[] valores = new string[3]; valores[0] = (string)AspSession.Get("user"); valores[1] = (string)AspSession.Get("logok"); valores[2] = (string)AspSession.Get("username"); int valor = 1; string urlParametro = string.Empty; foreach (string param in valores) { urlParametro += "Valor" + valor.ToString() + "=" + param + "&"; valor++; } urlParametro = urlParametro.Substring(0, urlParametro.Length - 1); string strOrden = string.Empty; string strSess = string.Empty; string strBoton = string.Empty; htmlTabla.Append("<table style='width: 80%; height: 100%;'>"); string siteName = ConfigurationManager.AppSettings["enlaceRet"].ToString(); string rutaServ = "http://" + Request.Url.Authority + "/" + siteName + "/"; string idLnk = string.Empty; int intFila = 0; foreach (DataRow reg in resultado.Rows) { strOrden = reg["orden"].ToString().Trim(); strSess = reg["programa"].ToString().Trim(); strBoton = "~/" + reg["boton"].ToString().Trim(); idLnk = "lnk_" + strSess.Replace(".aspx?flag=Y", ""); if (idLnk.Contains("fusionp/")) { strSess += "?" + urlParametro; idLnk = idLnk.Replace("/fusionp/WebPages/", ""); idLnk = idLnk.Remove(0, idLnk.IndexOf("/") + 1); if (idLnk.IndexOf('?') > 0) { int cntCh = idLnk.Length - idLnk.IndexOf('?'); idLnk = idLnk.Remove(idLnk.IndexOf('?'), cntCh); } } idLnk = "lnk_" + idLnk.Replace(".aspx", ""); intFila = Convert.ToInt32(strOrden) % 4; switch (intFila) { case 1: htmlTabla.Append("<tr>"); htmlTabla.Append("<td align='center'>" + string.Format("<asp:HyperLink ID='{0}' runat='server' CssClass='ButtonsSendSave' " + "ImageUrl='{1}' NavigateUrl='{2}'></asp:HyperLink>", idLnk, strBoton, strSess) + "</td>"); break; case 2: htmlTabla.Append("<td align='center'>" + string.Format("<asp:HyperLink ID='lnk_{0}' runat='server' CssClass='ButtonsSendSave' " + "ImageUrl='{1}' NavigateUrl='{2}'></asp:HyperLink>", idLnk, strBoton, strSess) + "</td>"); // htmlTabla.Append("<td align='center' class='style3'><a href=" + strSess + "><img src=" + strBoton + "></a></td>"); break; case 3: htmlTabla.Append("<td align='center'>" + string.Format("<asp:HyperLink ID='lnk_{0}' runat='server' CssClass='ButtonsSendSave' " + "ImageUrl='{1}' NavigateUrl='{2}'></asp:HyperLink>", idLnk, strBoton, rutaServ + strSess) + "</td>"); //htmlTabla.Append("<td align='center' class='style3'><a href=" + strSess + "><img src=" + strBoton + "></a></td>"); break; case 0: htmlTabla.Append("<td align='center'>" + string.Format("<asp:HyperLink ID='lnk_{0}' runat='server' CssClass='ButtonsSendSave' " + "ImageUrl='{1}' NavigateUrl='{2}'></asp:HyperLink>", idLnk, strBoton, rutaServ + strSess) + "</td>"); //htmlTabla.Append("<td align='center' class='style3'><a href=" + strSess + "><img src=" + strBoton + "></a></td>"); htmlTabla.Append("</tr>"); break; } } htmlTabla.Append("</table>"); return(htmlTabla); }