How do I resolve this exception thrown while trying to do CRUD operations on CSOM?

xarzu

New Member
Joined
Apr 1, 2013
Messages
15
How do I resolve this exception thrown while trying to do CRUD operations on CSOM?

Let me break this down for you. CRUD, of course, means "Create Read Update and Delete". CSOM is the tech for connection C# to a Sharepoint List (or, I assume, also a Microsoft List) in order to programmatically make additions or mortifications to said list from C# code.

I think that, due to the fact that the Microsoft List resides on a highly secure remote source dripping with security systems, I get an exception thrown when I set up a query and perform an "ExecuteQuery" from the ClientContext class. I can provide some source code if necessary but I do not think it is necessary. The question I have is simply this. What would cause a 403 Forbidden error and how can I find a way to resolve it?

CSOM-6.png


CSOM-7.png


Here is the details of the System.Net.WebException error:

System.Net.WebException
HResult=0x80131509
Message=The remote server returned an error: (403) Forbidden.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Dashboard.frmSettings.btnProcess_Click(Object sender, EventArgs e) in C:\source\Dashboard\Dashboard\frmSettings.cs:line 635

This exception was originally thrown at this call stack:
[External Code]
Dashboard.frmSettings.btnProcess_Click(object, System.EventArgs) in frmSettings.cs

What looks most important to me is:
System.Net.WebException HResult=0x80131509

Before I dig into this issue any further, I would like to take a moment and ask some simplier questions which could lead to answers that might help:
1. In order to make sure I am able to access the Microsoft List from the server, I am using a username and password in setting up the ClientContext class like this:

Code:
Using (ClientContext ctx = new ClientContext("(URL TO THE SHAREPOING SITE)"))
            {
                ctx.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtPassword.Text);
            }

So, let me ask this. Could the issue be as simple as the fact that the password has to be some sort of special string class? I remember seeing something about this one time.
I dismissed it because I thought it was some sort of APP.CONFIG thing used with ASP.NET

Now, if this, that I just mentioned is not the issue, then let's continue. Microsoft should provide a way to programmatically interface with low code or no code solutions and if they pride themselves in providing solutions for developers, then they products they offer for solutions.

Bing is a Microsoft product. Perhaps Bing's AI product "Copilot" can provide some answers.

I asked Bing Copilot:
hOW DO i FIX System.Net.WebException HResult=0x80131509

Copilot said:
The System.Net.WebException with HResult=0x80131509 often occurs when there’s an issue with the underlying connection. Let’s explore some potential solutions:

1. Check the Server:
o Verify that the server you’re connecting to is operational and not experiencing issues. Look at logs or event viewer entries for any clues.
o Ensure that you’re connecting to the correct server (consider proxy settings, etc.).
o Check the HTTP status code returned in the response (if available).

2. Exception Tracking:
o Wrap your code in exception-catching blocks and print out the full stack trace. This can provide more information about the problem.
o Consider enabling network tracing to see what’s happening over the wire.

3. Disable Expect100Continue:
o In some cases, setting System.Net.ServicePointManager.Expect100Continue to false can resolve the issue.
o You can do this with: System.Net.ServicePointManager.Expect100Continue = false;

4. Ensure TLS Support:
o If you’re using PowerShell, enable TLS by adding this line before your Invoke-RestMethod or Invoke-WebRequest call: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls3.
o For C# applications, ensure you’re using the most recent version of the .NET Framework.

5. Override GetWebRequest Method:
o Add a method to your class that overrides GetWebRequest. This allows you to access the HttpWebRequest object.

So, this leads me to the following questions:

1. How do I "Check the Server"? How would I verify that the server I am connecting to is operational nad not experiencing issues? I am able to log into the dasbboard account (we literally call it "dashboard") and from there I am able to freely look at our Microsoft List and view it in grid or row style. Doesn't that mean that the network connection checks out? What, specifically, do I need to do to further check the network?
2. This leads me to "Consider enabling network tracing to see what’s happening over the wire". How do I do that?
3. I tried adding the line System.Net.ServicePointManager.Expect100Continue = false; prior to the line of code that causes the exception to be thrown and it did not fix the problem
4. it says "For C# applications, ensure you’re using the most recent version of the .NET Framework.". How do I know I am using the latest version of the .NET Framework and where do I go to get the latest version. This might solve the problem.
5. How do I add a method to my class that overrides GetWebRequest?

Doing a search to find how to fix this 403 Forbidden error I found some information on the file and folder permissions and fixing it by setting the permissions to the file and the folder. I don't have the ability to do that, but I do have the ability to go into Microsoft List and get a link for permissions to edit. I tried using this link but I still got the 403 Forbidden error while stepping through my code.

CSOM-8.png


Please advise.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
This being primarily an Excel forum, you would be far better off posting this in a forum aimed at C# developers.
 
Upvote 0
This being primarily an Excel forum, you would be far better off posting this in a forum aimed at C# developers.
OK, but I thought I might luck out because SharePoint seems to be part of the Microsoft Office 365 package.
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top