none
Logging into a web page RRS feed

  • Question

  • I am trying to write a C# app that logs into a web page for me. The actual web page with the login is http://www.site.com/login.

    When I monitor the connection the credentials are actually passed to http://www.site.com/security_check. 

    I cannot get this to work I keep getting error 401 "Unauthorized Access" on both pages. Can anyone direct me to a good page that explains how to login? I have googled the hell out of it I keep getting use httpwebrequest then use 

    logInRequest.Credentials = new NetworkCredential(dealerName, passWord);

    Here is the whole request I have tried. Just copied pasted off a message board. I believe its a JSON login but I am not 100% on that. 

    //proxy request
                string MyProxyHostString = "192.168.1.200";
                int MyProxyPort = 8080;
    
                // Login request 
                HttpWebRequest logInRequest = WebRequest.Create("https://site.com/security_check") as HttpWebRequest;
                logInRequest.Proxy = new WebProxy(MyProxyHostString, MyProxyPort);
                //login request params
                logInRequest.Method = "GET";
                logInRequest.KeepAlive = true;
                logInRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                logInRequest.UseDefaultCredentials = true;
                logInRequest.Credentials = new NetworkCredential(userName, passWord);
                logInRequest.ContentType = "application/json";
                //get cookie from Web API
                HttpWebResponse response = (HttpWebResponse)logInRequest.GetResponse();
                foreach (Cookie cookieValue in response.Cookies)
                {
                    Console.Write("Cookie: " + cookieValue.ToString());
                    //store in your winform application
                }
                //get content
                string myResponse = "";
                using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    myResponse = sr.ReadToEnd();
                }


    Wednesday, March 21, 2018 10:40 PM

All replies

  • I think you send credentials into webpage through request credentials but you must send POST data which will simulate login form is filled. 

    What type of login is supported by web page? Form/windows?

    Wednesday, March 21, 2018 11:20 PM
  • I got this from another post. Its weird when I send it as post I get that method isnt allowed. But it is a post request. I captured the actual request in burp. 
    Wednesday, March 21, 2018 11:57 PM
  • Hi Quarinteen,

    Thank you for posting here.

    For your question, what is the type of your project? ASP.NET? 

    If your question is related to ASP.NET, please post a new thread in ASP.NET forum for suitable support.

    Here is a link about Form authentication and authorization in ASP.NET for your reference.

    https://www.codeproject.com/Articles/13872/Form-authentication-and-authorization-in-ASP-NET

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, March 22, 2018 6:55 AM
  • The URL you say you are using does not work. It is not the real URL.

    It is totally possible that the site is doing the login in a totally different way. Unless you have some information stating that it is compatible with NetworkCredential then it is unlikely it is.



    Sam Hobbs
    SimpleSamples.Info

    Thursday, March 22, 2018 10:10 PM