Tuesday, July 17, 2012

Error Type in Restful Service: {"error": {"code": "", "message": {"lang": "en-US", "value": "Forbidden"}}}

NOTE: Hi friends, this post related to .Net.

Here my function for update user using OData Service:


function UpdateUser(userId) {
             var updateUserdata = { UserId: 'test', FirstName: 'Accepted', LastName: 'Rejected' };
             var requestURI = USERS_ODATA_SVC + "(" + userId + ")";

             var requestOptions = {
                 requestUri: requestURI,
                 method: "PUT",
                 data: updateUserdata
             };
             OData.request(requestOptions);

         }


Am getting response error like this:

{"error": {"code": "", "message": {"lang": "en-US", "value": "Forbidden"}}}


I spent nearly 5 hours and find out the Cause for this error 

 public static void InitializeService(DataServiceConfiguration config)
        {
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);     -> here initially i gave like this, but it should be "EntitySetRights.All "
             config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        }

 this is the cause for 403 - Forbidden error in ADO.Net datasevice.

No comments:

Post a Comment