protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { bool isCorsRequest = request.Headers.Contains(Origin); bool isPreflightRequest = request.Method == HttpMethod.Options; if (isCorsRequest) { var response = new HttpResponseMessage(HttpStatusCode.OK); string domains = UtilityExtensions.GetKeyAppSetting(Commonkey.Domains); string allowMethods = UtilityExtensions.GetKeyAppSetting(Commonkey.AllowMethods); string allowHeaders = UtilityExtensions.GetKeyAppSetting(Commonkey.AllowHeaders); if (isPreflightRequest) { response.Headers.Add(AccessControlAllowOrigin, domains); response.Headers.Add(AccessControlAllowMethods, allowMethods); response.Headers.Add(AccessControlAllowHeaders, allowHeaders); var tcs = new TaskCompletionSource <HttpResponseMessage>(); tcs.SetResult(response); return(tcs.Task); } return(base.SendAsync(request, cancellationToken).ContinueWith(t => { HttpResponseMessage resp = t.Result; resp.Headers.Add(AccessControlAllowOrigin, domains); return resp; })); } return(base.SendAsync(request, cancellationToken)); }
public AccountController() { commonFn = new CommonFn(); requestUriLogin = UtilityExtensions.GetKeyAppSetting(MT.Library.Commonkey.mscUriLogin); }