Morning All,
I have a strange problem, with Webdav and Exchange (2003). I have
coded a vb.net Webdav app to pull in calender information and it works
just fine – but only for users who do not have a SBS/Exchange user
code with spaces in their name.
If I run it for a user of say “support”, it works and everything is
great. But if I run it for a user of “John Smith”, I get a 404 Not
Found error. I have tried changing the URL to “John%20Smith” and
“John+Smith” – none makes a difference.
Can anybody advise?
My code is as follows:
strUserName = "Jaffa Brown"
strPassword = "edger"
strDomain = "TouchstoneSystems.local"
strCalendarURI = "https://touchstoneserv/exchange/" &
strUserName & "/calendar"
' Build the SQL query.
strQuery = "<?xml version=""1.0""?>" & _
"<g:searchrequest xmlns:g=""DAV:"">" & _
"<g:sql>SELECT
""urn:schemas:calendar:location"", ""urn:schemas:httpmail:subject"", "
& _
"""urn:schemas:calendar:dtstart"",
""urn:schemas:calendar:dtend"", " & _
"""urn:schemas:calendar:busystatus"",
""urn:schemas:calendar:instancetype"" " & _
"FROM Scope('SHALLOW TRAVERSAL OF """ &
strCalendarURI & """') " & _
"WHERE NOT
""urn:schemas:calendar:instancetype"" = 1 " & _
"AND ""DAV:contentclass"" = 'urn:content-
classes:appointment' " & _
"AND ""urn:schemas:calendar:dtstart"" >
'2003/06/01 00:00:00' " & _
"ORDER BY ""urn:schemas:calendar:dtstart"" ASC"
& _
"</g:sql></g:searchrequest>"
' Create the PUT HttpWebRequest object.
Request = CType(System.Net.WebRequest.Create
(strCalendarURI), _
System.Net.HttpWebRequest)
Request.CookieContainer = New CookieContainer()
Request.CookieContainer.Add(AuthenticateSecureOWA
("touchstoneserv", strDomain, strUserName, strPassword))
Request.Credentials = New System.Net.NetworkCredential( _
strUserName, strPassword, strDomain)
Request.Method = "SEARCH"
Request.ContentType = "text/xml"
Request.KeepAlive = True
Request.AllowAutoRedirect = False
Dim gotbytes As Byte() = System.Text.Encoding.UTF8.GetBytes
(strQuery)
Request.Timeout = 30000
Request.ContentLength = gotbytes.Length
RequestStream = Request.GetRequestStream()
RequestStream.Write(gotbytes, 0, gotbytes.Length)
RequestStream.Close()
Request.Headers.Add("Translate", "F")
ServicePointManager.CertificatePolicy = New
MyCertificateValidation
Response = Request.GetResponse()
ResponseStream = Response.GetResponseStream()
And the OWA subroutine….
Private Function AuthenticateSecureOWA(ByVal strServerName As String,
ByVal strDomain As String, ByVal strUserName As String, ByVal
strPassword As String) As CookieCollection
Dim AuthURL As System.Uri
Try
' Construct our destination URI.
AuthURL = New System.Uri("https://" + strServerName + "/
exchweb/bin/auth/owaauth.dll")
Catch ex As Exception
MsgBox("Error occurred while you are creating the URI for
OWA authentication!" + vbCrLf + vbCrLf + ex.Message)
End Try
'Dim WebReq As HttpWebRequest
CookieJar = New CookieContainer
' Create our request object for the constructed URI.
WebReq = CType(WebRequest.Create(AuthURL), HttpWebRequest)
WebReq.CookieContainer = CookieJar
' Create our post data string that is required by OWA
(owaauth.dll).
Dim strPostFields As String = "destination=https%3A%2F%2F" &
strServerName & "%2Fexchange%2F" + strUserName + "%2F&username=" +
strDomain + "%5C" + strUserName + "&password=" + strPassword +
"&SubmitCreds=Log+On&forcedownlevel=0&trusted=0"
'Dim strPostFields As String = "destination=https%3A%2F%2F" &
strServerName & "%2Fexchange%2F" + strUserName + "%2F&username=" +
strDomain + "%5CJaffa%20Brown&password=" + strPassword +
"&SubmitCreds=Log+On&forcedownlevel=0&trusted=0"
WebReq.KeepAlive = True
WebReq.AllowAutoRedirect = False
WebReq.Method = "POST"
' Store the post data into a byte array.
Dim PostData() As Byte = System.Text.Encoding.ASCII.GetBytes
(strPostFields)
' Set the content length.
WebReq.ContentLength = PostData.Length
ServicePointManager.CertificatePolicy = New
MyCertificateValidation
Dim tmpStream As Stream
Try
' Create a request stream. Write the post data to the
stream.
tmpStream = WebReq.GetRequestStream()
tmpStream.Write(PostData, 0, PostData.Length)
tmpStream.Close()
Catch ex As Exception
MsgBox("Error occurred while trying OWA authentication!" +
vbCrLf + vbCrLf + ex.Message)
End Try
' Get the response from the request.
Dim WebResp As HttpWebResponse = WebReq.GetResponse()
WebResp.Close()
Return WebResp.Cookies
End Function