I have a MVC web application which uses Windows Authentication. So we do things like System.Web.HttpContext.Current.User.Identity.Name
Now there is a console app I'm writing that would be run as part of a batch job. All this console app needs to do is call an ActionResult in the main web app which would then carry out some maintenance tasks.
Now, since the console app doesn't have an identity within the domain controller/Active Directory, the call using System.Net.WebClient().DownloadString() keeps throwing a 401 error. 
My question is, is there a way to allow this application to call this link in the main web app without having to disable WindowsAuthentication in the web.config/IIS?
Any ideas/suggestions welcome.
All the console app contains is
static void Main(string[] args)
        {
            try
            {
                new System.Net.WebClient().DownloadString(System.Configuration.ConfigurationSettings.AppSettings["http://foo.com/"]);
            }
            catch
            {
            }
        }
Use UseDefaultCredentials:
        var client = new WebClient
                     {
                         UseDefaultCredentials = true
                     };
        client.DownloadString(address);
this will use whatever the console app is running as (which can be specified on the Scheduled Task settings).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With