Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WebDAV Issues After Upgrade to Exchange 2003

Reply
Thread Tools

WebDAV Issues After Upgrade to Exchange 2003

 
 
George Durzi
Guest
Posts: n/a
 
      11-06-2004
We recently upgraded to Exchange2K3/W2K3 from Exchange2K/W2K, and some of my
c# code that I used to access users' contacts using WebDAV has stopped
working. I'm getting a 401 unauthorized error. Hopefully, I can explain this
adequately.

Prior to the upgrade the following code was working properly.
FYI: The site was running in the context of the domain administrator, and
was also using the Administrator account to create a CredentialCache to
access Exchange

This function accepts my URI:
http://myMailServer/exchange/userLog.../?Cmd=contents

#region FetchContactsXml
private string FetchContactsXml(string sSourceURL)
{
StringBuilder sbPayload = new StringBuilder();
sbPayload.Append("<?xml version=\"1.0\"?>");
sbPayload.Append("<a:searchrequest xmlns:a=\"DAV:\">");
sbPayload.Append("<sql> SELECT \"urn:schemas:contacts:fileas\" ");
sbPayload.Append(", \"urn:schemas:contacts:givenName\" ");
sbPayload.Append(", \"urn:schemas:contacts:sn\" ");
sbPayload.Append(", \"urn:schemas:contacts\" ");
sbPayload.Append("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
sbPayload.Append("Where \"DAV:isfolder\" = false AND \"DAV:contentclass\"
");
sbPayload.Append("= 'urn:content-classeserson'");
sbPayload.Append(" ORDER BY \"urn:schemas:contacts:fileas\" ASC");
sbPayload.Append("</>");
sbPayload.Append("</>");

// Array to hold Xml Payload
byte[] arPayload = null;

try
{
// Get Payload and Encode it to utf-8
arPayload = Encoding.UTF8.GetBytes((string)sbPayload.ToString( ));

// Create HTTP Web Request & Set Properties
HttpWebRequest oWebRequest =
(System.Net.HttpWebRequest)HttpWebRequest.Create(s SourceURL);
oWebRequest.Method = "SEARCH";
oWebRequest.ContentType = "text/xml";
oWebRequest.ContentLength = arPayload.Length;

// Inject the Search Payload into the RequestStream
Stream oRequestStream = oWebRequest.GetRequestStream();
oRequestStream.Write(arPayload, 0, arPayload.Length);
oRequestStream.Close();

// Set Credentials to Access Exchange Store
oWebRequest.Credentials = CreateCredentialCache(sSourceURL);

// Create the Web Response Object
System.Net.WebResponse oWebResponse = (System.Net.WebResponse)
oWebRequest.GetResponse();
// Get the Xml Response Stream
Stream oStream = oWebResponse.GetResponseStream();
// utf-8 handle it
Encoding oEncoding = System.Text.Encoding.GetEncoding("utf-8");
StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
// Get the WebDAV Xml into a string
string sXmlData = oStreamReader.ReadToEnd();

// Clean Up
oStreamReader.Close();
oStream.Close();
oWebResponse.Close();

// Return the Xml string
return sXmlData;
}
catch (Exception oException)
{
ExceptionManager.Publish(oException);
throw(oException);
}
}
#endregion

#region CreateCredentialCache
private CredentialCache CreateCredentialCache(string sSourceURL)
{
try
{
CredentialCache oCredentialCache = new CredentialCache();
oCredentialCache.Add(
new System.Uri(sSourceURL),
"NTLM",
new NetworkCredential(
ConfigurationSettings.AppSettings["ExchangeAdminAccount"].ToString(),
@ConfigurationSettings.AppSettings["ExchangeAdminAccountPwd"].ToString(),
ConfigurationSettings.AppSettings["DomainName"].ToString()));

return oCredentialCache;
}
catch (Exception oException)
{
ExceptionManager.Publish(oException);
throw(oException);
}
}
#endregion

As I said, all of this worked perfectly before the upgrade. Now apparently
Exchange 2003 doesn't allow the Administrator account to have permissions on
all other account by default - which is a good thinkg since I shouldn't have
been using that anyway. So our exchange admin created an account for me to
use with the necessary permissions.

I verified that the account he created can access a user's contacts folder
by browsing to http://myMailServer/exchange/userLog.../?Cmd=contents
and logging in as DOMAIN\account, password. I was able to open any user's
contacts folder that I wanted to.


Ok, so after the upgrade, the code breaks at the following spot:
Stream oRequestStream = oWebRequest.GetRequestStream();

I noticed that this is before I even attached the CredentialCache, so I
tried moving that to above that point in code, but no change.

The exact exception is:

The remote server returned an error: (401) Unauthorized.


When building the CredentialCache in the CreateCredentialCache function, I
am using that new account I noted that our exchange admin created.

Any help is appreciated.


 
Reply With Quote
 
 
 
 
Tom Rizzo [MSFT]
Guest
Posts: n/a
 
      11-13-2004
And you're not running forms-based authentication or frontend/backend OWA or
anything like that? See if the Exchange Explorer can access your folders
since that's a WebDAV client as well.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp



"George Durzi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> We recently upgraded to Exchange2K3/W2K3 from Exchange2K/W2K, and some of
> my c# code that I used to access users' contacts using WebDAV has stopped
> working. I'm getting a 401 unauthorized error. Hopefully, I can explain
> this adequately.
>
> Prior to the upgrade the following code was working properly.
> FYI: The site was running in the context of the domain administrator, and
> was also using the Administrator account to create a CredentialCache to
> access Exchange
>
> This function accepts my URI:
> http://myMailServer/exchange/userLog.../?Cmd=contents
>
> #region FetchContactsXml
> private string FetchContactsXml(string sSourceURL)
> {
> StringBuilder sbPayload = new StringBuilder();
> sbPayload.Append("<?xml version=\"1.0\"?>");
> sbPayload.Append("<a:searchrequest xmlns:a=\"DAV:\">");
> sbPayload.Append("<sql> SELECT \"urn:schemas:contacts:fileas\" ");
> sbPayload.Append(", \"urn:schemas:contacts:givenName\" ");
> sbPayload.Append(", \"urn:schemas:contacts:sn\" ");
> sbPayload.Append(", \"urn:schemas:contacts\" ");
> sbPayload.Append("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
> sbPayload.Append("Where \"DAV:isfolder\" = false AND
> \"DAV:contentclass\" ");
> sbPayload.Append("= 'urn:content-classeserson'");
> sbPayload.Append(" ORDER BY \"urn:schemas:contacts:fileas\" ASC");
> sbPayload.Append("</>");
> sbPayload.Append("</>");
>
> // Array to hold Xml Payload
> byte[] arPayload = null;
>
> try
> {
> // Get Payload and Encode it to utf-8
> arPayload = Encoding.UTF8.GetBytes((string)sbPayload.ToString( ));
>
> // Create HTTP Web Request & Set Properties
> HttpWebRequest oWebRequest =
> (System.Net.HttpWebRequest)HttpWebRequest.Create(s SourceURL);
> oWebRequest.Method = "SEARCH";
> oWebRequest.ContentType = "text/xml";
> oWebRequest.ContentLength = arPayload.Length;
>
> // Inject the Search Payload into the RequestStream
> Stream oRequestStream = oWebRequest.GetRequestStream();
> oRequestStream.Write(arPayload, 0, arPayload.Length);
> oRequestStream.Close();
>
> // Set Credentials to Access Exchange Store
> oWebRequest.Credentials = CreateCredentialCache(sSourceURL);
>
> // Create the Web Response Object
> System.Net.WebResponse oWebResponse = (System.Net.WebResponse)
> oWebRequest.GetResponse();
> // Get the Xml Response Stream
> Stream oStream = oWebResponse.GetResponseStream();
> // utf-8 handle it
> Encoding oEncoding = System.Text.Encoding.GetEncoding("utf-8");
> StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
> // Get the WebDAV Xml into a string
> string sXmlData = oStreamReader.ReadToEnd();
>
> // Clean Up
> oStreamReader.Close();
> oStream.Close();
> oWebResponse.Close();
>
> // Return the Xml string
> return sXmlData;
> }
> catch (Exception oException)
> {
> ExceptionManager.Publish(oException);
> throw(oException);
> }
> }
> #endregion
>
> #region CreateCredentialCache
> private CredentialCache CreateCredentialCache(string sSourceURL)
> {
> try
> {
> CredentialCache oCredentialCache = new CredentialCache();
> oCredentialCache.Add(
> new System.Uri(sSourceURL),
> "NTLM",
> new NetworkCredential(
> ConfigurationSettings.AppSettings["ExchangeAdminAccount"].ToString(),
>
> @ConfigurationSettings.AppSettings["ExchangeAdminAccountPwd"].ToString(),
> ConfigurationSettings.AppSettings["DomainName"].ToString()));
>
> return oCredentialCache;
> }
> catch (Exception oException)
> {
> ExceptionManager.Publish(oException);
> throw(oException);
> }
> }
> #endregion
>
> As I said, all of this worked perfectly before the upgrade. Now apparently
> Exchange 2003 doesn't allow the Administrator account to have permissions
> on all other account by default - which is a good thinkg since I shouldn't
> have been using that anyway. So our exchange admin created an account for
> me to use with the necessary permissions.
>
> I verified that the account he created can access a user's contacts folder
> by browsing to
> http://myMailServer/exchange/userLog.../?Cmd=contents and logging
> in as DOMAIN\account, password. I was able to open any user's contacts
> folder that I wanted to.
>
>
> Ok, so after the upgrade, the code breaks at the following spot:
> Stream oRequestStream = oWebRequest.GetRequestStream();
>
> I noticed that this is before I even attached the CredentialCache, so I
> tried moving that to above that point in code, but no change.
>
> The exact exception is:
>
> The remote server returned an error: (401) Unauthorized.
>
>
> When building the CredentialCache in the CreateCredentialCache function, I
> am using that new account I noted that our exchange admin created.
>
> Any help is appreciated.
>
>



 
Reply With Quote
 
 
 
 
George Durzi
Guest
Posts: n/a
 
      11-15-2004
Tom,
Sorry, I'm not too experienced with administering Exchange. Is the Exchange
Explorer when you actually browse in IE to
http:\\exchserver\exchange\login\Inbox, etc..?

If so, yes it works

"Tom Rizzo [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> And you're not running forms-based authentication or frontend/backend OWA
> or anything like that? See if the Exchange Explorer can access your
> folders since that's a WebDAV client as well.
>
> Tom
>
> --
> Looking for a good book on programming Exchange, Outlook, ADSI and
> SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp
>
>
>
> "George Durzi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> We recently upgraded to Exchange2K3/W2K3 from Exchange2K/W2K, and some of
>> my c# code that I used to access users' contacts using WebDAV has stopped
>> working. I'm getting a 401 unauthorized error. Hopefully, I can explain
>> this adequately.
>>
>> Prior to the upgrade the following code was working properly.
>> FYI: The site was running in the context of the domain administrator, and
>> was also using the Administrator account to create a CredentialCache to
>> access Exchange
>>
>> This function accepts my URI:
>> http://myMailServer/exchange/userLog.../?Cmd=contents
>>
>> #region FetchContactsXml
>> private string FetchContactsXml(string sSourceURL)
>> {
>> StringBuilder sbPayload = new StringBuilder();
>> sbPayload.Append("<?xml version=\"1.0\"?>");
>> sbPayload.Append("<a:searchrequest xmlns:a=\"DAV:\">");
>> sbPayload.Append("<sql> SELECT \"urn:schemas:contacts:fileas\" ");
>> sbPayload.Append(", \"urn:schemas:contacts:givenName\" ");
>> sbPayload.Append(", \"urn:schemas:contacts:sn\" ");
>> sbPayload.Append(", \"urn:schemas:contacts\" ");
>> sbPayload.Append("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
>> sbPayload.Append("Where \"DAV:isfolder\" = false AND
>> \"DAV:contentclass\" ");
>> sbPayload.Append("= 'urn:content-classeserson'");
>> sbPayload.Append(" ORDER BY \"urn:schemas:contacts:fileas\" ASC");
>> sbPayload.Append("</>");
>> sbPayload.Append("</>");
>>
>> // Array to hold Xml Payload
>> byte[] arPayload = null;
>>
>> try
>> {
>> // Get Payload and Encode it to utf-8
>> arPayload = Encoding.UTF8.GetBytes((string)sbPayload.ToString( ));
>>
>> // Create HTTP Web Request & Set Properties
>> HttpWebRequest oWebRequest =
>> (System.Net.HttpWebRequest)HttpWebRequest.Create(s SourceURL);
>> oWebRequest.Method = "SEARCH";
>> oWebRequest.ContentType = "text/xml";
>> oWebRequest.ContentLength = arPayload.Length;
>>
>> // Inject the Search Payload into the RequestStream
>> Stream oRequestStream = oWebRequest.GetRequestStream();
>> oRequestStream.Write(arPayload, 0, arPayload.Length);
>> oRequestStream.Close();
>>
>> // Set Credentials to Access Exchange Store
>> oWebRequest.Credentials = CreateCredentialCache(sSourceURL);
>>
>> // Create the Web Response Object
>> System.Net.WebResponse oWebResponse = (System.Net.WebResponse)
>> oWebRequest.GetResponse();
>> // Get the Xml Response Stream
>> Stream oStream = oWebResponse.GetResponseStream();
>> // utf-8 handle it
>> Encoding oEncoding = System.Text.Encoding.GetEncoding("utf-8");
>> StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
>> // Get the WebDAV Xml into a string
>> string sXmlData = oStreamReader.ReadToEnd();
>>
>> // Clean Up
>> oStreamReader.Close();
>> oStream.Close();
>> oWebResponse.Close();
>>
>> // Return the Xml string
>> return sXmlData;
>> }
>> catch (Exception oException)
>> {
>> ExceptionManager.Publish(oException);
>> throw(oException);
>> }
>> }
>> #endregion
>>
>> #region CreateCredentialCache
>> private CredentialCache CreateCredentialCache(string sSourceURL)
>> {
>> try
>> {
>> CredentialCache oCredentialCache = new CredentialCache();
>> oCredentialCache.Add(
>> new System.Uri(sSourceURL),
>> "NTLM",
>> new NetworkCredential(
>> ConfigurationSettings.AppSettings["ExchangeAdminAccount"].ToString(),
>>
>> @ConfigurationSettings.AppSettings["ExchangeAdminAccountPwd"].ToString(),
>> ConfigurationSettings.AppSettings["DomainName"].ToString()));
>>
>> return oCredentialCache;
>> }
>> catch (Exception oException)
>> {
>> ExceptionManager.Publish(oException);
>> throw(oException);
>> }
>> }
>> #endregion
>>
>> As I said, all of this worked perfectly before the upgrade. Now
>> apparently Exchange 2003 doesn't allow the Administrator account to have
>> permissions on all other account by default - which is a good thinkg
>> since I shouldn't have been using that anyway. So our exchange admin
>> created an account for me to use with the necessary permissions.
>>
>> I verified that the account he created can access a user's contacts
>> folder by browsing to
>> http://myMailServer/exchange/userLog.../?Cmd=contents and logging
>> in as DOMAIN\account, password. I was able to open any user's contacts
>> folder that I wanted to.
>>
>>
>> Ok, so after the upgrade, the code breaks at the following spot:
>> Stream oRequestStream = oWebRequest.GetRequestStream();
>>
>> I noticed that this is before I even attached the CredentialCache, so I
>> tried moving that to above that point in code, but no change.
>>
>> The exact exception is:
>>
>> The remote server returned an error: (401) Unauthorized.
>>
>>
>> When building the CredentialCache in the CreateCredentialCache function,
>> I am using that new account I noted that our exchange admin created.
>>
>> Any help is appreciated.
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an appointment in an exchange calendar using webdav (slide) Bernhard Weitlaner Java 11 12-15-2010 09:08 PM
WebDAV: Connect Ruby to a WebDAV Server Michael Dichtl Ruby 7 07-09-2007 04:42 PM
Using WEBDAV to create draft on Exchange Server funnycoder ASP .Net 0 07-25-2006 06:45 PM
Exchange WebDAV - PUT Request - 501 not implemented =?Utf-8?B?bWFyaWEucw==?= ASP .Net 3 09-01-2005 07:51 AM
Apache Slide - Exchange 2003 - WebDav Request KovaiRam Java 1 02-01-2005 11:14 PM



Advertisments