Please Help : The remote server returned an error: (401) Unauthorized

Discussion in 'Software' started by adarsh.vishnoi, Jun 5, 2008.

  1. adarsh.vishnoi

    adarsh.vishnoi

    Joined:
    Jun 5, 2008
    Messages:
    1
    Hi I am facing The remote server returned an error: (401) Unauthorized error on following code when i use it on other server

    private int LogonToProjectServer()
    {

    if (sCookie != "") return 1;
    string sURL = "";

    try
    {
    sURL = txtURL.ToString() + "/LgnIntAu.asp";

    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(sURL);
    CookieContainer conCookie = new CookieContainer();

    NetworkCredential objNC = new NetworkCredential(@"sankalp_d", "kaiser@123456", "assigncorp");

    //myReq.Credentials = CredentialCache.DefaultCredentials;
    myReq.Credentials = objNC;
    myReq.CookieContainer = conCookie;


    //This line of code is necessary in order to work with SSL enabled
    // Project Server sites - see the SSL Certificate Handling Class below.
    ServicePointManager.CertificatePolicy = new MyCertificateValidation();

    // Return the response.

    HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse();

    XmlDocument XMLDoc = new XmlDocument();
    XMLDoc.Load(myRes.GetResponseStream());
    // Close the response to free resources.
    myRes.Close();
    sCookie = GetLogonStatus(XMLDoc);
    Response.Write("Hi : " + sCookie);
    if (sCookie.Length < 10)
    {
    lblMessage.Visible = true;
    lblMessage.Text = lblMessage.Text + " Microsoft Project Server logon failed.\nLogon Status = " + sCookie;
    sCookie = "";
    return 0;
    }
    }
    catch (WebException ex)
    {
    string mess;
    if (ex.Response == null)
    {
    mess = "Logon Exception Occurred\n" + ex.Message;
    }
    else
    {
    mess = "Logon Exception Occurred\n" + ex.Message + "\n" + ex.Response.ResponseUri.AbsoluteUri + "string url" + sURL;
    }

    lblMessage.Visible = true;
    lblMessage.Text = lblMessage.Text + mess;
    return 0;
    }
    return 1;
    }
    adarsh.vishnoi, Jun 5, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James
    Replies:
    9
    Views:
    27,734
    James
    Mar 6, 2006
  2. mark shannon

    Finepix 401

    mark shannon, Jul 14, 2003, in forum: Digital Photography
    Replies:
    2
    Views:
    445
    mark shannon
    Jul 14, 2003
  3. Dwayne Wheat

    HELP! Unauthorized access to home computer

    Dwayne Wheat, Jan 22, 2005, in forum: Computer Security
    Replies:
    5
    Views:
    507
    Michael J. Pelletier
    Jan 23, 2005
  4. Mike Dorn
    Replies:
    0
    Views:
    362
    Mike Dorn
    Sep 22, 2006
  5. Thaqalainnaqvi@gmail.com

    Runtime Error or 401 Authorisation required?

    Thaqalainnaqvi@gmail.com, Sep 26, 2006, in forum: Computer Support
    Replies:
    1
    Views:
    840
    Kluck
    Sep 26, 2006
Loading...

Share This Page