I've a client application that contains mostly the front end code. For example in the login screen a remote api is called to authenticate the user against a database. This works fine in forms authentication but when basic authentication is implement i get 401 error. The sample code is as below. Kindly help.
string data = JsonConvert.SerializeObject(loginUser); cookie = RemoteData ("/authenticateuser", "POST", data);
private string RemoteData(string url, string Method, string data) {
string result = "";
var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
try
{
using (var client = new WebClient { UseDefaultCredentials = true })
{
client.Headers.Add(HttpRequestHeader.ContentType, "application/json; charset=utf-8");
byte[] buffer =client.UploadData(_apiPath + url, "POST", Encoding.UTF8.GetBytes(data));
result=Encoding.UTF8.GetString(buffer, 0, buffer.Length);
return result;
}
}
catch (Exception exc)
{
return "";
}
finally
{
wic.Undo();
}
}
I got the above code from http://msdn.microsoft.com/en-us/library/ff647405.aspx . Editing registry is out of question. What can i do to get things working
Thanxs in Advance
Pradeep