Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am making a page in SharePoint that is used to proxy other content in SharePoint. The user is authenticated at the time they hit this proxy page, but I am getting an Unauthorized Access error.

The page has the following code behind:

var request = (HttpWebRequest) WebRequest.Create(urlToProxy);
request.Method = "GET";
request.Credentials = CredentialCache.DefaultNetworkCredentials; //This isn't working, apparently
var response = (HttpWebResponse) request.GetResponse();

My first thought was to use the credentials from the incoming WebRequest, but this is an HttpRequest and doesn't seem to have the Credentials property.

Does anyone know how I can pass the user's existing logged in credentials to this outgoing HttpWebRequest?

share|improve this question
    
Is this NTLM, Kerberos or Claims? –  Dave Wise Feb 28 '13 at 22:49
    
It is NTLM. Thanks. –  MgSam Mar 5 '13 at 19:13

1 Answer 1

It sounds like you are facing the infamous double-hop issue. In a nutshell, with NTLM you are authenticated to the server, but your credentials cannot be used by the server to access other servers.

Here is a good MSDN blog post explaining it: http://blogs.msdn.com/b/besidethepoint/archive/2010/05/09/double-hop-authentication-why-ntlm-fails-and-kerberos-works.aspx

Basically you either have to use a service account (one you can access the credentials for in your code, storing them in the web.config or in the Secure Store Service) or use a different authentication method that lets you pass the credentials (i.e. kerberos).

share|improve this answer
    
Ok, so to get around that, I'm now trying to hardcode specific credentials just for this proxy page. I'm trying do request.Credentials = new NetworkCredential(@"username", "password"){Domain = "domain"} but this isn't working. Any ideas what's wrong here? –  MgSam Mar 1 '13 at 21:54
    
You might try creating a Credential Cache that you add your credentials to. See the end of blogs.msdn.com/b/buckh/archive/2004/07/28/199706.aspx for an example. –  John Chapman Mar 1 '13 at 21:58
    
CredentialCache cache = new CredentialCache(); cache.Add(new Uri("example.com"), "Negotiate", loginCredentials); cache.Add(new Uri("redirected.example.com"), "Negotiate", loginCredentials); request.Credentials = cache; - See more at: efreedom.com/Question/1-4918682/… –  John Chapman Mar 1 '13 at 22:00
    
This works for certain SharePoint pages, but unfortunately not the Office Web Apps, which is what I am trying to proxy. I'll post a solution if I find one. Thanks for your help. –  MgSam Mar 5 '13 at 19:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.