none
System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse() RRS feed

  • Question

  • Hi to all ,

    In auto-hosted apps i added custom list without code using feature ,now i deploy that apps in online sharepoint site 2013. Now i want to fetch item from that list using CSOM in Clienthost web part than i got the error and error is

    System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse() and following code i am using for fetching the data from list

     ClientContext clientContext = new ClientContext("https://snapchamp-d4fb71a65ae947.sharepoint.com/");
                    Web web = clientContext.Web;
                    List list = web.Lists.GetByTitle("TOD");
                    CamlQuery query = CamlQuery.CreateAllItemsQuery();
                    Microsoft.SharePoint.Client.ListItemCollection itemcoll = list.GetItems(query);
                   
                    clientContext.Load(itemcoll);
                    clientContext.ExecuteQuery();

    foreach (Microsoft.Sahrepoint.client.ListItem item in itemColl)
    {
    // Display the item title field value
    Label1.Text = item["Title"].ToString();
    }

    Friday, December 20, 2013 1:26 PM

Answers

  • Hi,                                                             

    I suggest you use the code below in a console application for a simple test:

    using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))
    {
        SecureString passWord = new SecureString();
        foreach (char c in "yourpassword".ToCharArray()) passWord.AppendChar(c);
        clientContext.Credentials = new SharePointOnlineCredentials("loginname@yoursite.onmicrosoft.com", passWord);
        Web web = clientContext.Web;
        clientContext.Load(web);
        clientContext.ExecuteQuery();
        Console.WriteLine(web.Title);
        Console.ReadLine();
    }

    A blog about Authenticating .NET Client Object Model for your reference:

    http://www.vrdmn.com/2013/01/authenticating-net-client-object-model.html

    Best regards


    Patrick Liang
    TechNet Community Support

    Monday, December 23, 2013 6:56 AM
    Moderator