tags:

views:

154

answers:

1

I am working on a project that is click-once deployed from an IIS 7.5 web server. After installing the parent application (i.e. setting up the IIS site) I am able to hit the url for the click-once app's config file from a remote box.
HOWEVER, when I attempt to do the same thing from my app (and the stub app below), I get a 401 Unauthorized.

What is the difference between hitting the URL from IE, and from a .NET app?
The file and directory itself have full control granted to everyone on the webserver at the moment, and I am an admin on the box. We are using Windows Authentication with NTLM only.

Thanks, -Bob

Here is the stub app that produces the 401 - Unauthorized when on the doc.Load() line. I can hit the same URL successfully from IE and open the file...

static void Main(string[] args)
    {
        Console.WriteLine("Config Test");
        string filename = "http://dev-rs/myClient/myClickOnce/myApp.config.xml";
        Console.WriteLine(filename);
        XmlDocument doc = new XmlDocument();
        doc.Load(filename);
        Console.WriteLine("Loaded");
        Console.WriteLine("Inner Text : " + doc.InnerText);
    }
+1  A: 

Establish the principle:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

XMLDocument does not support passing credentials when loading from a URL. Instead load from a WebRequest stream and set the credentials on the request before the load.

WebRequest request = HttpWebRequest.Create(filename);
request.Credentials = CredentialCache.DefaultCredentials;

XmlDocument doc = new XmlDocument();
doc.Load(request.GetResponse().GetResponseStream());
Mark Lindell
that did the trick! Noticed I wasnt doing that on a subsequent webService call from app...had to set the credentials there with CredentialCache.DefaultCredentials as well.
Bob