I am getting a ‘401 – Not Authorized’ error message returned when I attempt to delete a single record from a database table using Entity Framework.
The database table definitely has the correct permissions and the .svc file for entity framework is set to:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
The code I am using for the delete in my application is very simple:
MyObject myObj = this.MyObjects.SingleOrDefault(t => t.RecordID == recordID);
svc.DeleteObject(myObj);
svc.SaveChanges();
‘MyObject’ refers to an item from an EntityObject which I have extracted into lists.
The code seems correct, as it recognises the object to be deleted. The following log entry shows what is happening on the service:
2012-02-27 11:06:02 192.XXX.X.XXX DELETE
/MyService.svc/MyObjects(19) – 8010 – 192.XXX.X.X> Microsoft+ADO.NET+Data+Services 401 0 0 1
Can anyone shed any light on why this might be happening?
EDIT: Fetching data and adding new lines to the same table currently works with no problems.
Turns out it is some kind of issue with file permissions on the actual .svc file.
I solved the problem by granting my ApplicationPool identity for the service Modify permissions on the /MyService.svc file.
I picked up this tip from this post: http://social.msdn.microsoft.com/Forums/eu/adodotnetdataservices/thread/987b5808-d1d3-41a6-be80-206ead679f46