Authentification à OWA en vb.net, bug dans mon code

schumileboss Messages postés 32 Date d'inscription dimanche 24 octobre 2004 Statut Membre Dernière intervention 23 avril 2008 - 21 juil. 2006 à 13:33
schumileboss Messages postés 32 Date d'inscription dimanche 24 octobre 2004 Statut Membre Dernière intervention 23 avril 2008 - 21 juil. 2006 à 15:27
Bonjour,

Je souhaitais savoir si l'un d'entre vous saurait comment s'authentifier à owa en VB.net afin d'ajouter par la suite des rendez vous aux users.

Mon code est le suivant pour l'instant mais ne fonctionne pas.

 
Private Function GetRequestObject(ByVal uri As String, ByVal method As String) As HttpWebRequest 
Dim webRequest1 As HttpWebRequest 
Dim credentials As String() 
Dim cache As CredentialCache 
Dim uri2 As Uri 

'Initiate a new WebRequest to the given URI. 
uri2 = New Uri(uri) 

webRequest1 = WebRequest.Create(uri2) 
webRequest1.CookieContainer = New CookieContainer 
webRequest1.Method = method 

Return webRequest1 
End Function 


 
Private Function DoFormBasedAuthentication(ByVal uri As String, ByVal credential As NetworkCredential) As CookieCollection 
Dim server As String '= ConfigurationSettings.AppSettings("smtpServer") 
Dim request As HttpWebRequest 
Dim response As HttpWebResponse 
Dim body As Byte() 
Dim stream1 As Stream 
Dim result As String 

Try 
'Get the server portion of the requested uri and appen the authentication dll from Exchange 
'server = "http://" & server & "/exchweb/bin/auth/owaauth.dll" 
server = uri.Substring(0, uri.IndexOf("/", ) + "/exchweb/bin/auth/owaauth.dll" 
'server = "http://chronos/exchange" 
request = GetRequestObject(server, "POST") 
request.CookieContainer = New CookieContainer 
request.ContentType = "application/x-www-form-urlencoded" 
'Prepare the body of the request 
body = Encoding.UTF8.GetBytes(String.Format("destination={0}&username={1}\\{2}&password={3}", uri, credential.Domain, credential.UserName, credential.Password)) 
request.ContentLength = body.Length 
'Send the request to the server 
stream1 = request.GetRequestStream 
stream1.Write(body, 0, body.Length) 
stream1.Close() 
'Get the response 
response = request.GetResponse 
'Check if the login was successful 
If (response.Cookies.Count < 2) Then 
'Throw New Exception("Failed to login OWA.") 
End If 

Return response.Cookies 

Catch ex As Exception 
'Throw New Exception("Failed to login to OWA. The following error occured : " + ex.StackTrace) 
'PublishException(ex) 
Dim coco As String 
coco = "coucou" 
End Try 
End Function 


Dans le page load:

 
Label1.Text = "" 
Try 
Label1.Text = "TEST : " 
Dim cookieColl As CookieCollection 
Dim netCred As NetworkCredential = New System.Net.NetworkCredential(strAlias, strPassword, strDomain) 
Label1.Text += strMailboxURI &amp; " " &amp; netCred.Domain &amp; " " &amp; netCred.UserName &amp; " " &amp; netCred.Password &amp; " " 
cookieColl = DoFormBasedAuthentication(strMailboxURI, netCred) 
Label1.Text &amp;= "nbCo : " &amp; cookieColl.Count.ToString &amp; " " 
'Dim item As Cookie 
'For Each item In cookieColl 
' Label1.Text &amp;= " " &amp; item.Name &amp; item.Value 
'Next 
Catch ex As Exception 
Label1.Text &amp;= "ERREUR : " &amp; ex.StackTrace 
End Try 



Mon problème est que la fonction DoFormBasedAuthentication renvoie nothing.
Du coup, la ligne
 
Label1.Text &amp;= "nbCo : " &amp; cookieColl.Count.ToString &amp; " " 

Jette une exception.

Merci.
Mickael

2 réponses

cs_azra Messages postés 425 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 13 juillet 2007 1
21 juil. 2006 à 14:35
Bonjour,

Plutot que de manipuler l'interface web, une meilleure approche serai de manipuler le serveur exchange qui se situe derriere?
A moins que tu ais des contraintes techniques?

<hr />Azra(Florent) - MVS- MCSD.NET
0
schumileboss Messages postés 32 Date d'inscription dimanche 24 octobre 2004 Statut Membre Dernière intervention 23 avril 2008
21 juil. 2006 à 15:27
J'ai repris l'application en main récement, donc jvais pas tout refaire, surtout que beaucoup de choses serais à refaire.
Donc j'essaie d'adapter cette application afin qu'elle fonctionne.
Enfait nous utilision l'authentification windows intégré mais le client pour des raison qui sont propres souhaite changer l'uthentification en authentification par formulaire.

merci
0
Rejoignez-nous