Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900