WebClient, UseDefaultCredentials, IIS, WindowsAuthentication, and TaskScheduler

454 Views Asked by At

I have written a .NET console app that fetches some values from an intranet web app using System.Net.WebClient with UseDefaultCredentials = true. The web app uses Windows Authentication and allows all users logged into the network and denies anonymous users:

<authentication mode="Windows"/>

<authorization>      
  <allow users="*" />    
  <deny users= "?"/>
</authorization>

The console app works fine when I run it on my PC by double-clicking on the program's EXE file. It does what it's supposed to do.

However, when the same program is run on the same PC as a scheduled task using TaskScheduler, it cannot establish communication with the intranet web app.

The console app is set to run under a particular user account —my own— the same account I'm using when double-clicking on the program's exe, and it is set to run whether the user is logged in or not. I have also tried with "Run with the highest privileges" enabled and disabled.

When configuring the task, TaskScheduler asks for the run-account password, which I supply. The option to prevent the password from being stored is not checked.

Is the problem here in the context of TaskScheduler that my WebClient subclass is set to use UseDefaultCredentials = true?

P.S. I should also add that the program's Main() routine is testing for command line arguments and assuming that if they exist, args[1] and args[2] contain particular values it needs and if not, it uses default values. Does TaskScheduler supply any command line arguments to the executables it launches? I am assuming that it does not do so.

0

There are 0 best solutions below