'Redirect from asp.net web api post action doesn't seem to work

As a new comer to ASP.Net looking for workaround on, redirecting to another URL at the end of the HttpResponseMessage POST api.

In reference to Redirect from asp.net web api post action I tried same procedure to redirect. Api returns response to caller but no redirect is happening. The Api call response goes to fail callback on javascript side.

Any suggestion on solving this is greatly appreciated.

Tried calling Post API from Javascript. Always throws error with CORS.

// C# API

[HttpPost] 
[Route("SignInTest")] 
public HttpResponseMessage Post(SignInModel signInModel)
 {
    HttpResponseMessage response = null; 
    EntityResponse<UserAuthenticationDTO> userAuthenticationDTOResponse =         
       _authenticationService.Validate(signInModel.Login, signInModel.Password); 
    if (userAuthenticationDTOResponse.IsSuccess) 
    {
       var response = new HttpResponseMessage(HttpStatusCode.Redirect);
       response.Headers.Location = new Uri("https://sample.com"); // to url that I have to redirect
       return response; // expected https://sample.com to load 
    } 
    response = Request.CreateResponse(HttpStatusCode.InternalServerError,     ErrorCode.AccountVerificationEmailIsNotVerified); 
    return response;
 }

// Javascript Caller
dataContext.singleSignOn.SignInTest(self.validatedObservable).done(function (data)
{
   console.log("data", data);
}).fail(function (error) 
{
   console.log("done with error", error); // Always throws error with CORS for https://sample.com to load .
  
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source