Passing Credentials to WEBDAV

S

Steve Drake

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 :

MyCredentialCache.Add( new System.Uri(strRootURI),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);


Request.Credentials = CredentialCache.MyCredentialCache;

it works, but I don't want to hard code the username / pass and the username
/ pass must be the current user as this is an exchange WEBDAV request.



Steve
 
S

Steve Drake

I've added

<identity impersonate= "true" />

But this is not ideal as this is a WEBCONTROL ( Server Control) and I don't
want to insist that the user of the control have this option set.

Steve
 
S

SF

Impersonation seems to be the right thing to do here. Without it,
you will get the aspnet-user credentials from the credential cache
which is why the authentication failed in the first place.

Can you elaborate why it isn't ideal for you?

Also, a good article/library on accessing Exchange with WebDAV
is here: http://www.codeproject.com/dotnet/exdav.asp?print=true

Might be worth checking out
-Stefan
 
S

Steve Drake

I am writing reusable server controls that can be use from a WEBPART
(sharepoint) or a webcontrol in a standard ASP.NET, so I don't want to be
force into changing the config of the webserver for that implementation.

but... if I have to then that's how it has to work.

Steve
 
S

SF

In this case, you could try to make the WebDAV request and in case the
authentication fails, you could catch the Exception and redirect to a logon
form, where the user needs to provide the network credentials to use and
retry the request. Also, you can put the NetworkCredential object in session
and use it for subsequent WebDAV requests.

Is that viable?
 
S

Steve Drake

Sounds like a solutions, I will give it a try.


SF said:
In this case, you could try to make the WebDAV request and in case the
authentication fails, you could catch the Exception and redirect to a logon
form, where the user needs to provide the network credentials to use and
retry the request. Also, you can put the NetworkCredential object in session
and use it for subsequent WebDAV requests.

Is that viable?
 
P

Pedro Bernardo

I know it has been a long time from the last thread but i'm having this problem to ..

Dim Cache As New System.Net.CredentialCache
Dim credential As ICredentials = CredentialCache.DefaultCredentials
Dim strAuthType As String = "Negotiate" 'Kerberos or NTLM return the same error
Dim uri1 As New System.Uri("http://exchange.gruporr.pt/exchange/pedro.bernardo")
Cache.Add(uri1, strAuthType, credential)
Dim session As WebdavSession = New WebdavSession("http://exchange.gruporr.pt/exchange/pedro.bernardo", Cache)

this is a simple webform app that i'm running on my localhost webserver IIS. The strange is that, when a changing the line : "Dim credential As ICredentials = CredentialCache.DefaultCredentials" to : "Dim credential As ICredentials = New System.Net.NetworkCredential("pedrobernardo", "mypassord", "mydomain")", it doesn't return the 401 error, instead it works fine.
Can you help me on this ?
Tks in advance
PedroBernardo


From http://www.developmentnow.com/g/8_2003_12_0_0_166740/Passing-Credentials-to-WEBDAV.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
B

Bruce Barker

if this code in in a webapp, then the DefaultCredentials are the asp.net
account, which will not have network access. if you set identity
impersonate="true" in the web config, it should work from you local host.
note: the one hop rule will prevent it working if the browser is not on the
same server as the iis, unless you switch to kerberos and enable creditials
delegation on your servers.


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top