简体   繁体   中英

Default Credentials work in 1 project but not in another?

I have a web service that uploads documents to Sharepoint and works fine using

System.Net.ICredentials creds = System.Net.CredentialCache.DefaultCredentials;
context.Credentials = creds;

I have re-used this code in another project and I get the error:

System.Net.WebException was unhandled by user code
Message=The remote server returned an error: (401) Unauthorized.

As far as I can see everything is the same in the config files and don't know why its failing. Any ideas?

I solved it for anyone who might come across a problem like this.

The problem is in IIS, it is using the default application pools. Simply change it from default to your custom pool where the "Identity" field is your PC name or Login Credentials. This can be done to the default App pool, however, if you have existing projects using this pool, it is advisable to create a new App pool so you don't break existing projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM