Session du client

cs_adoulti Messages postés 8 Date d'inscription vendredi 14 décembre 2007 Statut Membre Dernière intervention 22 juin 2008 - 14 juin 2008 à 12:38
cs_adoulti Messages postés 8 Date d'inscription vendredi 14 décembre 2007 Statut Membre Dernière intervention 22 juin 2008 - 15 juin 2008 à 16:38
bonsoir,
j'ai une méthode d' authentification dans un web service    WS_authentification 
, elle ça marche bien , voici le code si dessouuuuuuuuus(à la fin de ce message)

dans ma web form d'authentification  j'ai le code suivant

protectedvoid Page_Load(object sender, EventArgs e)
{
                 WS_authentification aut = newWS_authentification();
                  if (Session["UserNum"] != null)
                                    Response.Redirect("reservation1.aspx");
}

protected

void Button1_Click(object sender, EventArgs e)
{
         WS_authentification authentification = newWS_authentification();
          bool res = authentification.authentifier(login.Text, mp.Text);
         if (res == true)
                  Response.Redirect("reservation1.aspx");
}
=>le résultat si je clique sur le bouton "Button1_Click" il m' affiche la page
reservation1.aspx

mon problème si j'ajoute à la page reservation1.aspx ce code

if

(Session["UserNum"] == null)
Response.Redirect("authentification.aspx");
Label1.Text = Session["UserNum"].ToString();pour entrer à la session. si je clique sur le bouton "Button1_Click" il ne m'affiche pas la page
reservation1.aspx et il reste à la page d'authentification
quel est mon erreur??  merci de votre colaboration
excusez moi si le choix de thème est false
/////////***********////

[

WebMethod(
true)]
public

bool authentifier(
string login,
string mp)
{

System.Data.SqlClient.

SqlConnection connexion;
connexion =

new System.Data.SqlClient.
SqlConnection();
string

connectString =
"Data Source=STANDARD;"+

"Initial Catalog=SejoursHOTEL;"+

"User ID=sa;"+

"Password=administrateur;";
string

strQuery =
"select * from T_CLIENT";
connexion.ConnectionString = connectString;

System.Data.SqlClient.

SqlCommand oCommand =
new System.Data.SqlClient.
SqlCommand(strQuery, connexion);
connexion.Open();

SqlDataReader

oReader = oCommand.ExecuteReader();
int

b = -1;
bool

returnBool =
false;
while

(oReader.Read())
{

if (oReader[8].ToString() == login && oReader[9].ToString() == mp)
{

try { Session[
"user"] = oReader[0].ToString();
returnBool =

true;
}

catch (
Exception e){
return
false;}
}

}

oReader.Close();

connexion.Close();

return

returnBool;
}

4 réponses

WishhhMaster Messages postés 327 Date d'inscription mardi 17 février 2004 Statut Membre Dernière intervention 10 avril 2010 8
14 juin 2008 à 14:10
Salut,

C'est tout bête, mais ça ne serait pas session["UserNum"] = oReader[0].ToString(); au lieu de
Session[
"user"] = oReader[0].ToString();

Sinon tu devrais mettre tes
oReader.Close(); et connexion.Close();

dans une clause finally, sinon la connexion et le reader ne seront pas fermés si une exception se produit.
0
cs_adoulti Messages postés 8 Date d'inscription vendredi 14 décembre 2007 Statut Membre Dernière intervention 22 juin 2008
14 juin 2008 à 16:25
salut,
oui mr cé ma faute excusez moi,
bon je corige cette faute e j'ajoute le finally aussi
mais il reste un problème je ne connais pas comment envoyer à la page suivante les variables que j'ai besoin.
j'ai utiliser la methode response.redirect elle ça marche bien sans session si j'ajoute la session , aucune variable est envoyé
Response.Redirect(

"reservation1.aspx?hot=" + DDL_hotel.SelectedValue +
"&age_bebe1=" + agebebe +
"&age_enf1=" + ageenf);

///////////code de la methode authentification dans un web service///////////

[

WebMethod(
true)]
public

bool authentifier(
string login,
string mp)
{System.Data.SqlClient.

SqlConnection connexion;
connexion =
new System.Data.SqlClient.
SqlConnection();

string connectString =
"Data Source=STANDARD;"
+
"Initial Catalog=SejoursHOTEL;"
+
"User ID=sa;"
+
"Password=administrateur;";

string strQuery =
"select * from T_CLIENT where (sa_Log_CLI='"+login+
"' and sa_MP_CLI='"+mp+
"')";connexion.ConnectionString = connectString;
System.Data.SqlClient.

SqlCommand oCommand =
new System.Data.SqlClient.
SqlCommand(strQuery, connexion);
connexion.Open();

SqlDataReader oReader = oCommand.ExecuteReader();

bool returnBool =
false;

try {

            if (oReader.Read()){ 
            Session[
"user"] = oReader[0].ToString();
            returnBool =
true;

            return returnBool;
}

else
             return
false;
}

catch (
Exception e){
return
false;}

finally
{
oReader.Close();
connexion.Close();
}
}
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
14 juin 2008 à 16:38
2 remarques :
- renseignes toi sur le concept de requêtes paramétrées
- le compte sa n'a strictement rien à faire dans une application ! c'est un compte d'administration

En résumé tu as ici un risque d'injection SQL avec un potentiel assez intéressant vu le compte utilisé...

/*
coq
MVP Visual C#
CoqBlog
*/
0
cs_adoulti Messages postés 8 Date d'inscription vendredi 14 décembre 2007 Statut Membre Dernière intervention 22 juin 2008
15 juin 2008 à 16:38
salut,
pour string connectString =
"Data Source=STANDARD;"
                                           +
"Initial Catalog=SejoursHOTEL;" 
                                           +
"User ID=sa;" 
                                           +
"Password=administrateur;";

j'ai utilisé cet instruction "sa" pour se connecter à ma base "SejoursHOTEL"
si vous avez une autre solution pour se connecter à la base, merci de me l'envoyer.
 aussi s'il ya une autre façon d'authentification et d'autres instructions pour la session( que l'on ajoute à les pages qui dépondent de l'authentification), merci de m'informer et de me l'envoyer.

merci pour votre réponse
0
Rejoignez-nous