So I have a bunch of requests that I need to do from c# to a web api and they need basic authentication. I know I can do something like this:
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://url"); String username = "abc"; String password = "123"; String encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); httpWebRequest.Headers.Add("Authorization", "Basic " + encoded); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST";
but I don't want to manually add the credentials into the header for every request. I'm wondering if there's a way through which I can globally authenticate all my requests (from web.config, perhaps something similar to connectionStrings for sql connections?).