473,769 Members | 6,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebDAV Issues After Upgrade to Exchange 2003

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 FetchContactsXm l
private string FetchContactsXm l(string sSourceURL)
{
StringBuilder sbPayload = new StringBuilder() ;
sbPayload.Appen d("<?xml version=\"1.0\" ?>");
sbPayload.Appen d("<a:searchreq uest xmlns:a=\"DAV:\ ">");
sbPayload.Appen d("<sql> SELECT \"urn:schemas:c ontacts:fileas\ " ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:givenNa me\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:sn\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:o\" ");
sbPayload.Appen d("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
sbPayload.Appen d("Where \"DAV:isfolder\ " = false AND \"DAV:contentcl ass\"
");
sbPayload.Appen d("= 'urn:content-classes:person' ");
sbPayload.Appen d(" ORDER BY \"urn:schemas:c ontacts:fileas\ " ASC");
sbPayload.Appen d("</>");
sbPayload.Appen d("</>");

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

try
{
// Get Payload and Encode it to utf-8
arPayload = Encoding.UTF8.G etBytes((string )sbPayload.ToSt ring());

// Create HTTP Web Request & Set Properties
HttpWebRequest oWebRequest =
(System.Net.Htt pWebRequest)Htt pWebRequest.Cre ate(sSourceURL) ;
oWebRequest.Met hod = "SEARCH";
oWebRequest.Con tentType = "text/xml";
oWebRequest.Con tentLength = arPayload.Lengt h;

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

// Set Credentials to Access Exchange Store
oWebRequest.Cre dentials = CreateCredentia lCache(sSourceU RL);

// Create the Web Response Object
System.Net.WebR esponse oWebResponse = (System.Net.Web Response)
oWebRequest.Get Response();
// Get the Xml Response Stream
Stream oStream = oWebResponse.Ge tResponseStream ();
// utf-8 handle it
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf-8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
// Get the WebDAV Xml into a string
string sXmlData = oStreamReader.R eadToEnd();

// Clean Up
oStreamReader.C lose();
oStream.Close() ;
oWebResponse.Cl ose();

// Return the Xml string
return sXmlData;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#endregion

#region CreateCredentia lCache
private CredentialCache CreateCredentia lCache(string sSourceURL)
{
try
{
CredentialCache oCredentialCach e = new CredentialCache ();
oCredentialCach e.Add(
new System.Uri(sSou rceURL),
"NTLM",
new NetworkCredenti al(
ConfigurationSe ttings.AppSetti ngs["ExchangeAdminA ccount"].ToString(),
@ConfigurationS ettings.AppSett ings["ExchangeAdminA ccountPwd"].ToString(),
ConfigurationSe ttings.AppSetti ngs["DomainName "].ToString()));

return oCredentialCach e;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#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.Get RequestStream() ;

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 CreateCredentia lCache function, I
am using that new account I noted that our exchange admin created.

Any help is appreciated.
Nov 18 '05 #1
2 2792
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" <gd****@hotmail .com> wrote in message
news:OI******** ******@TK2MSFTN GP10.phx.gbl...
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 FetchContactsXm l
private string FetchContactsXm l(string sSourceURL)
{
StringBuilder sbPayload = new StringBuilder() ;
sbPayload.Appen d("<?xml version=\"1.0\" ?>");
sbPayload.Appen d("<a:searchreq uest xmlns:a=\"DAV:\ ">");
sbPayload.Appen d("<sql> SELECT \"urn:schemas:c ontacts:fileas\ " ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:givenNa me\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:sn\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:o\" ");
sbPayload.Appen d("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
sbPayload.Appen d("Where \"DAV:isfolder\ " = false AND
\"DAV:contentcl ass\" ");
sbPayload.Appen d("= 'urn:content-classes:person' ");
sbPayload.Appen d(" ORDER BY \"urn:schemas:c ontacts:fileas\ " ASC");
sbPayload.Appen d("</>");
sbPayload.Appen d("</>");

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

try
{
// Get Payload and Encode it to utf-8
arPayload = Encoding.UTF8.G etBytes((string )sbPayload.ToSt ring());

// Create HTTP Web Request & Set Properties
HttpWebRequest oWebRequest =
(System.Net.Htt pWebRequest)Htt pWebRequest.Cre ate(sSourceURL) ;
oWebRequest.Met hod = "SEARCH";
oWebRequest.Con tentType = "text/xml";
oWebRequest.Con tentLength = arPayload.Lengt h;

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

// Set Credentials to Access Exchange Store
oWebRequest.Cre dentials = CreateCredentia lCache(sSourceU RL);

// Create the Web Response Object
System.Net.WebR esponse oWebResponse = (System.Net.Web Response)
oWebRequest.Get Response();
// Get the Xml Response Stream
Stream oStream = oWebResponse.Ge tResponseStream ();
// utf-8 handle it
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf-8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
// Get the WebDAV Xml into a string
string sXmlData = oStreamReader.R eadToEnd();

// Clean Up
oStreamReader.C lose();
oStream.Close() ;
oWebResponse.Cl ose();

// Return the Xml string
return sXmlData;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#endregion

#region CreateCredentia lCache
private CredentialCache CreateCredentia lCache(string sSourceURL)
{
try
{
CredentialCache oCredentialCach e = new CredentialCache ();
oCredentialCach e.Add(
new System.Uri(sSou rceURL),
"NTLM",
new NetworkCredenti al(
ConfigurationSe ttings.AppSetti ngs["ExchangeAdminA ccount"].ToString(),

@ConfigurationS ettings.AppSett ings["ExchangeAdminA ccountPwd"].ToString(),
ConfigurationSe ttings.AppSetti ngs["DomainName "].ToString()));

return oCredentialCach e;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#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.Get RequestStream() ;

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 CreateCredentia lCache function, I
am using that new account I noted that our exchange admin created.

Any help is appreciated.

Nov 18 '05 #2
Tom,
Sorry, I'm not too experienced with administering Exchange. Is the Exchange
Explorer when you actually browse in IE to
http:\\exchserv er\exchange\log in\Inbox, etc..?

If so, yes it works

"Tom Rizzo [MSFT]" <th*****@micros oft.com> wrote in message
news:O0******** ******@TK2MSFTN GP15.phx.gbl...
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" <gd****@hotmail .com> wrote in message
news:OI******** ******@TK2MSFTN GP10.phx.gbl...
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 FetchContactsXm l
private string FetchContactsXm l(string sSourceURL)
{
StringBuilder sbPayload = new StringBuilder() ;
sbPayload.Appen d("<?xml version=\"1.0\" ?>");
sbPayload.Appen d("<a:searchreq uest xmlns:a=\"DAV:\ ">");
sbPayload.Appen d("<sql> SELECT \"urn:schemas:c ontacts:fileas\ " ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:givenNa me\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:sn\" ");
sbPayload.Appen d(", \"urn:schemas:c ontacts:o\" ");
sbPayload.Appen d("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");
sbPayload.Appen d("Where \"DAV:isfolder\ " = false AND
\"DAV:contentcl ass\" ");
sbPayload.Appen d("= 'urn:content-classes:person' ");
sbPayload.Appen d(" ORDER BY \"urn:schemas:c ontacts:fileas\ " ASC");
sbPayload.Appen d("</>");
sbPayload.Appen d("</>");

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

try
{
// Get Payload and Encode it to utf-8
arPayload = Encoding.UTF8.G etBytes((string )sbPayload.ToSt ring());

// Create HTTP Web Request & Set Properties
HttpWebRequest oWebRequest =
(System.Net.Htt pWebRequest)Htt pWebRequest.Cre ate(sSourceURL) ;
oWebRequest.Met hod = "SEARCH";
oWebRequest.Con tentType = "text/xml";
oWebRequest.Con tentLength = arPayload.Lengt h;

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

// Set Credentials to Access Exchange Store
oWebRequest.Cre dentials = CreateCredentia lCache(sSourceU RL);

// Create the Web Response Object
System.Net.WebR esponse oWebResponse = (System.Net.Web Response)
oWebRequest.Get Response();
// Get the Xml Response Stream
Stream oStream = oWebResponse.Ge tResponseStream ();
// utf-8 handle it
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf-8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
// Get the WebDAV Xml into a string
string sXmlData = oStreamReader.R eadToEnd();

// Clean Up
oStreamReader.C lose();
oStream.Close() ;
oWebResponse.Cl ose();

// Return the Xml string
return sXmlData;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#endregion

#region CreateCredentia lCache
private CredentialCache CreateCredentia lCache(string sSourceURL)
{
try
{
CredentialCache oCredentialCach e = new CredentialCache ();
oCredentialCach e.Add(
new System.Uri(sSou rceURL),
"NTLM",
new NetworkCredenti al(
ConfigurationSe ttings.AppSetti ngs["ExchangeAdminA ccount"].ToString(),

@ConfigurationS ettings.AppSett ings["ExchangeAdminA ccountPwd"].ToString(),
ConfigurationSe ttings.AppSetti ngs["DomainName "].ToString()));

return oCredentialCach e;
}
catch (Exception oException)
{
ExceptionManage r.Publish(oExce ption);
throw(oExceptio n);
}
}
#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.Get RequestStream() ;

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 CreateCredentia lCache function,
I am using that new account I noted that our exchange admin created.

Any help is appreciated.


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1450
by: Li Weng | last post by:
Hi, I plan to use WebDAV to retrieve email remotely from Exchange 2003. But I can't find any sample codes in MSDN. Could you recommend some sample code sites? Thanks in advance. Li
0
939
by: Lev | last post by:
Hi all, How can I send an email message with attached files via WebDAV for Exchange (MS Exchange 2003)? Thx, Lev
0
1367
by: Lev | last post by:
Hi all, Anybody know how to send email message with attached files via WebDAV for Exchange (MS Exchange 2003 Server). Please, please, please! Need help! ASAP!!!! Tnx, Lev
7
4871
by: Steve Drake | last post by:
All, I am doing a WEBDAV request and I want to pass the users Credentials to the webdav server, eg some code like : Request.Credentials = CredentialCache.DefaultCredentials; This does not work, as I get AUTH FAIL, but if I pass the user name and password by using :
0
3873
by: Brian Henry | last post by:
I want to pull my contact list (personal one) from the exchange server into a local text file. I know how to write stuff into a text file, just getting it from an exchange server is my problem. I've been looking at webdav as a solution to this, but i dont know much about how to use webdav or it with exchange server. Right now i'm working with VB.NET I found a sample project at...
3
4022
by: maria.s | last post by:
Hi, I try to create a calender-item in the personal calendar folder from an ASP.NET application using XML-HTTP Request (WebDAV). System: Windows 2003 SP1, Exchange 2003 SP1 Configuration IIS: Default Web Site stopped, OWA running on a second virtual site, my application is running on a third virtual site.
0
3399
by: arjen1984 | last post by:
I am now working on C# with WebDAV on Exchange now to get appointments. When I work local on the domain where the server is, i can get the appointments no problem. When I work outside of it, i get an SecurityException. This is my code to get the appointments: protected void getAfspraken() { NetworkCredential credential = new NetworkCredential("bhees","1234567", "oaicttest"); WebdavSession session = new...
7
3489
by: Wiebe Tijsma | last post by:
Hi, I'm using C# + webDAV to create a draft message to be sent in a user's Drafts folder. I can create the message successfully, however when I open the message in outlook, it doesn't show the 'send' button, (only 'reply' etc as if it was a received message). I'm using exchange explorer to see the difference in webDAV properties
4
11095
by: DudDav | last post by:
Hi All, I have been trying to configured WebDAV on our current IIS server as an alternative to FTP and have had some mixed success but I've hit a brick wall with one problem. The server (Windows 2003 IIS 6) resides in the DMZ. I have created a virtual directory and directed it to a folder stored on the server. Integrated Windows Authentication and Basic Authentication has been enable along with SSL. I have added a handful of user account...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.