Ask for web auth if required

Ask for authentication to download private Khronos files.
This commit is contained in:
Fraser Waters 2015-03-01 14:44:28 +00:00
parent d7c21bd3f5
commit 7427f44bbe

View file

@ -49,7 +49,27 @@ namespace CHeaderToXML
using (var wb = new WebClient()) using (var wb = new WebClient())
{ {
string filename = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); string filename = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
wb.DownloadFile(path, filename);
try
{
wb.DownloadFile(path, filename);
}
catch (WebException e)
{
if (e.Message == "The remote server returned an error: (401) Unauthorized.")
{
System.Console.WriteLine(e.Message);
System.Console.Write("Username: ");
string username = System.Console.ReadLine();
System.Console.Write("Password: ");
string password = System.Console.ReadLine();
wb.UseDefaultCredentials = true;
wb.Credentials = new NetworkCredential(username, password);
wb.DownloadFile(path, filename);
}
}
contents = File.ReadAllLines(filename); contents = File.ReadAllLines(filename);
File.Delete(filename); File.Delete(filename);
} }