private Task<HttpResponseMessage> Unauthorized(HttpRequestMessage request) { var response = request.CreateResponse(HttpStatusCode.Unauthorized); response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue); var task = new TaskCompletionSource<HttpResponseMessage>(); task.SetResult(response); return task.Task; } private api_login ParseAuthorizationHeader(string authHeader) { string[] credentials = Encoding.ASCII.GetString(Convert.FromBase64String(authHeader)).Split(new[] { ':' }); if (credentials.Length != 2 || string.IsNullOrEmpty(credentials[0]) || string.IsNullOrEmpty(credentials[1])) return null; return new api_login() { username = credentials[0], password = credentials[1], }; } private bool TryGetPrincipal(string userName, string password, out IPrincipal principal) { // data access in a repository or separate layer/library. api_login user = repository.Validate2(userName, password); int failedAttempts = 0; if (user.username != null) { // once the user is verified, assign it to an IPrincipal with the identity name and applicable roles failedAttempts += 1; principal = new GenericPrincipal(new GenericIdentity(user.username), null); } else if (failedAttempts == 3) { //error message code } principal = null; return false; } }
else if (user.username == null) { //throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, String.Format("this identity does not exist"))); throw new HttpResponseException(HttpStatusCode.NotFound); }
ScriptManager.RegisterStartupScript(this,GetType(),"showalert","alert('Only alert Message');",true);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)