How can I authenticate a user (with username and password) of an ASP.NET MVC application? I\'m trying to do this using WebClient
, passing NetworkCredentials>
Forms authentication works in two steps:
So to achieve this in a WPF application you will need to first obtain an authentication cookie. So first send a POST request to the LogIn page along with the username and password and read the returned cookie (For this you need to set the CookieContainer property on the HttpWebRequest for it to be able to catch the cookie). Once you have the cookie you reuse the cookie container in subsequent calls to authenticated pages.
You may checkout this sample code to assist you (just replace the addresses and parameter names).