I realize this thread is a month or two old, but it drives me nuts when "you can't" responses becomes a permanent part of the internet landscape rather than a constructive community effort to solve the problem at hand.
netadmin:
Basic authentication encodes both the username and password in a HTTP header variable in base64 encoding. You can pull out this header, remove the string prefix, decode the base 64 string and split the output at the ':'.
Try something like this:
string requestUsername;
string requestPassword;
try
{
// The header is in the following format
// "Basic 64BitEncodedUsernameAndPasswordString"
string userAndPassEncoded = this.Context.Request.Headers["Authorization"].Substring(6);
// userAndPasswordDecoded is in the following
// format "theusername:thepassword"
string userAndPassDecoded = new System.Text.ASCIIEncoding().GetString(
Convert.FromBase64String(this.Context.Request.Headers["Authorization"].Substring(6)));
string[] userAndPasswordArray = userAndPassDecoded.Split(':');
requestUsername = userAndPasswordArray[0];
requestPassword = userAndPasswordArray[1];
}
catch (Exception ex)
{
throw new ApplicationException("Unable to get the Basic Authentication credentials from the request", ex);
}
Best Regards,