0

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?

1
  • Is this NTLM, Kerberos or Claims?
    – Dave Wise
    Commented Feb 28, 2013 at 22:49

1 Answer 1

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).

4
  • 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
    Commented Mar 1, 2013 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. Commented Mar 1, 2013 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/… Commented Mar 1, 2013 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
    Commented Mar 5, 2013 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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