Using Forms Based Authentication (FBA) on a desktop application in C#
- November 11th, 2009
- Posted in Tech Recipes . WCF
- By Germán Medina
- Write comment
To use FBA on a desktop client will be necessary to make a first request to the server and create the authentication cookie. This cookie will be used on the next requests to receive permission from the server to access protected resources imitating the browser’s behavior.
First we need to write a server side method that receives the login and password information, does the authentication task and creates the authentication cookie:
public bool Authenticate(String login, String password)
{
if (Membership.ValidateUser(login, password))
{
System.Web.Security.FormsAuthentication.SetAuthCookie(login, false);
return true;
}
else return false;
}
On the client side we need to make a request to the authentication method and copy the authentication cookie to the future requests (Here you will find an easy way to make post requests using C#):
Cookie cookie = authenticate_response.Cookies[".ASPXAUTH"]; new_request.CookieContainer = new CookieContainer(); new_request.CookieContainer.Add(cookie);
No comments yet.