Link to home
Start Free TrialLog in
Avatar of DCMBS
DCMBSFlag for United Kingdom of Great Britain and Northern Ireland

asked on

.Net 3.5 Breaks Webdav Authentication to exchange

I have an application coded in Microsoft Visual c# 2005 Express.  The application uses Webdav to access Outlook Calendars on an exchange 2003 server.  The application is installed on the exchange 2003 server.  The application has been in use without any problems for a number of years.  Recently I upgraded to Microsoft Visual c# 2008 express.  I compiled the application in c# 2008 wityhout making any changes to the code. It compiled OK and executed OK on my test machine.  However when I installed the updated version on my production server I was prompted to install .NET 3.5 SP1.  After installing this version of .NET the application is unable to access the outlook calendars. It returns a 401 not authorised error.  The application still works OK on a remote machine. I tried uninstalling .NET 3.5 SP1 and recompiling the application in Microsoft c# 2005 but I am still unable to access the outlook calendars when the application is executed on the local server.  It can however access the calendars OK when run on a remote server. I am sure this something that .NET 3.5 has broken on the exchange server.  Has anybody else experienced this issue when upgrading a server to .net 3.5 and has anybody any suggestions how to fix this.
Avatar of apache09
apache09
Flag of New Zealand image

Only issues I have heard with .NET 3.5 SP1 have been using Exchange Server 2007
http://support.microsoft.com/kb/958934

Perhaps there are some similar using 2003
Avatar of DCMBS

ASKER

This is the section of code that seems to have been broken by the installation of .net 3.5 sp1.

The exception is thrown at the call the line
           Response = (HttpWebResponse)Request.GetResponse();
This returns the following reponse
          The remote server returned an error: (401) Unauthorized.
This works OK when I run the routine on a remote server that has not had .net 3.5 sp1 installed, and used to work OK on this machine until .net 3.5 sp1 was installed so it seem that .net 3.5 sp 1 changes the way the (HttpWebResponse)Request.GetResponse() is processed, or perhaps it the way the credentials cache is handled??
Any ideas would be appreciated.



Code Extract.
            string strUserName = "XXXXXXXXX";
            string strPassword = "XXXXXXXX";
            string strDomain = "XXXXXXXX";
            byte[] bytes = null;

            System.Net.HttpWebRequest Request;
            System.Net.WebResponse Response;
            System.Net.CredentialCache MyCredentialCache;
            System.IO.Stream RequestStream;
            System.IO.Stream ResponseStream;
            System.Xml.XmlDocument ResponseXmlDoc;


            try
            {
                // Build the SQL query.            

                // Create a new CredentialCache object and fill it with the network
                // credentials required to access the server.
                MyCredentialCache = new System.Net.CredentialCache();
                MyCredentialCache.Add(new System.Uri(strCalendarURI),
                   "NTLM",
                   new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
                   );

                // Create the HttpWebRequest object.
                Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strCalendarURI);

                // Add the network credentials to the request.
                Request.Credentials = MyCredentialCache;

                // Specify the method.
                Request.Method = "SEARCH";

                // Encode the body using UTF-8.
                bytes = Encoding.UTF8.GetBytes((string)OutlookQry);

                // Set the content header length.  This must be
                // done before writing data to the request stream.
                Request.ContentLength = bytes.Length;

                // Get a reference to the request stream.
                RequestStream = Request.GetRequestStream();

                // Write the SQL query to the request stream.
                RequestStream.Write(bytes, 0, bytes.Length);

                // Close the Stream object to release the connection
                // for further use.
                RequestStream.Close();

                // Set the content type header.
                Request.ContentType = "text/xml";

                // Send the SEARCH method request and get the
                // response from the server.
                Response = (HttpWebResponse)Request.GetResponse();

                // Get the XML response stream.
                ResponseStream = Response.GetResponseStream();

                // Create the XmlDocument object from the XML response stream.
                ResponseXmlDoc = new XmlDocument();
                ResponseXmlDoc.Load(ResponseStream);
                ResponseStream.Close();
                Response.Close();
                return ResponseXmlDoc;
            }
            catch (Exception ex)
            {
                // Catch any exceptions. Any error codes from the SEARCH
                // method request on the server will be caught here, also.
                Console.Out.WriteLine(DateTime.Now + "Exception Thrown in getOutlookCalendarItems()");

                Console.Out.WriteLine(DateTime.Now + " Error accessing Outlook Calendar: " + strCalendarURI);
                //Console.Out.WriteLine(ex.Message.);
                // Console.Out.WriteLine(ex.InnerException.Message);
                return new XmlDocument();
                // string temp = Console.In.ReadLine();
            }
       
ASKER CERTIFIED SOLUTION
Avatar of DCMBS
DCMBS
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DCMBS

ASKER

To specify the host names that are mapped to the loopback address and can connect to Web sites on a local computer, follow these steps:

1. Click Start, click Run, type regedit, and then click OK.

2. In Registry Editor, locate and then click the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

3. Right-click MSV1_0, point to New, and then click Multi-String Value.

4. Type BackConnectionHostNames, and then press ENTER.

5. Right-click BackConnectionHostNames, and then click Modify.

6. In the Value data box, type the host name or the host names for the sites (the host name used in the request URL) that are on the local computer, and then click OK.

7. Quit Registry Editor, and then restart the IISAdmin service and run IISReset.