Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

Tuesday, January 29, 2013

How to fix: "The security validation for this page is invalid." error

When you want to programmatically update a column for a list or library item, an error similar to the below might be thrown.
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Now, I have many web methods which are updating many different libraries in my site, but this particular issue occurred on one of the web methods connected to one particular library. Though I have not been able to understand why, but I was able to resolve the issue by using the following command.
myWeb.AllowUnsafeUpdate = true;
myListItem["Status"] = "Approved";
myListItem.Update(); 
I still want to know the reason why only one of the web method and library needed this extra piece of code? All other web methods are updating library items without the use of this code.

I would appreciate your comments if you may know the reason for this. If you have found this helpful, let me know that too :)

Sunday, November 4, 2012

The web application at [URL] could not be found

Here is an error I encountered while calling the SPSite object using the URL:

The Web application at [URL] could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

It was the first time I encountered this and this is how I moved about resolving the issue

1. Checked if the URL was really not available.

That wasn't the case. The URL was very much valid and hence this option got eliminated.

2. Google search on this issue almost always pointed to the bit-ness of the platform. That the application was targeting x86 platform and SharePoint Server was x64 bit platform.

In my case, this wasn't true either. Both my platforms were on x86. It was easy to eliminate this option.

3. AAM, Alternate Access Mapping not done properly.

Wasn't an issue in my case. Any guesses? This option was eliminated as well.

4. The code is a windows or web service application which you are running with an account that does not have permissions to connect to SharePoint or SQL Server.

This is where I was at and out of it. This was the issue in my case. My web service code was running on the DefaultAppPool and the identity for the DefaultAppPool was Network Service Account.

I selected configurable and provided the username and password of a user who had elevated privileges.

It all worked and I hope it does for you as well!