1
我正在使用基本授權編寫RESTful服務。wcf 401並要求在RESTful服務中登錄/密碼
這是我做的時候沒有授權頭存在,或者當有錯誤UN /密碼
//Get authorization header
var auth = HttpContext.Current.Request.Headers.GetValues("Authorization");
if (auth == null)
{
outgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
return false;
}
//Parse auth header:
var authString = auth[0];
String loginName, password;
try
{
var decbuff = Convert.FromBase64String(authString.Replace("Basic ", ""));
loginName = System.Text.Encoding.UTF8.GetString(decbuff).Split(':')[0];
password = System.Text.Encoding.UTF8.GetString(decbuff).Split(':')[1];
}
catch
{
outgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
outgoingResponse.StatusDescription = "Invalid Authorization header";
return false;
}
當我看着菲德勒我看到這一點:
它的工作原理確定與我的客戶端(Android),但我希望這項服務可以通過瀏覽器或其他瀏覽器瀏覽。如果我發送401,我如何讓資源管理器詢問聯合國/密碼?我需要指定一些東西嗎?
謝謝