We have an ASP.NET web application that uses Forms authentication. We also have a WPF application which uses a Web browser control so it can use some pages from the web application. In order to authenticate users in WPF application, I created a Web API post method as follows:
public class LoginController : ApiController
{
[HttpPost]
public bool Post(LoginModel login)
{
User user;
var success = UserRepository.Authenticate(login.UserName, login.Password, out user);
if (success)
{
//FormsAuthentication.SetAuthCookie(login.UserName, true);
var authCookie = LedgexSession.CreateAuthorizationCookie(login.UserName, true);
System.Web.HttpContext.Current.Response.SetCookie(authCookie);
return true;
}
return false;
}
public class LoginModel
{
public string UserName { get; set; }
public string Password { get; set; }
}
}
This code works fine, and I am able to hit the Web Api method from postman and from my WPF application and get success as a return value. However, the WPF's web browser control still doesn't get the authenticated cookie, and anytime I open a page in the control, I am taken to the login screen. How can I set its cookie to the authenticated one I get from Web API?