简体   繁体   English

尝试从数据库表中删除单个记录时,实体框架'401 Not Authorized'

[英]Entity Framework '401 Not Authorised' when attempting delete of single record from database table

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. 当我尝试使用Entity Framework从数据库表中删除单个记录时,我收到了“401 - Not Authorized”错误消息。

The database table definitely has the correct permissions and the .svc file for entity framework is set to: 数据库表肯定具有正确的权限,实体框架的.svc文件设置为:

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. 'MyObject'指的是EntityObject中的一个项目,我将其提取到列表中。

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.XX> Microsoft+ADO.NET+Data+Services 401 0 0 1 2012-02-27 11:06:02 192.XXX.X.XXX DELETE /MyService.svc/MyObjects(19) - 8010 - 192.XXX.XX> 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. 编辑:获取数据和添加新行到同一个表目前没有问题。

It looks like your WCF service requires authorisation/authentication of some sort and you are not properly authorised. 看起来您的WCF服务需要某种授权/身份验证,并且您没有得到适当的授权。 Check your WCF config, and authenticate your client appropriately. 检查您的WCF配置,并相应地验证您的客户端。

Turns out it is some kind of issue with file permissions on the actual .svc file. 事实证明,对于实际的.svc文件,文件权限存在某种问题。

I solved the problem by granting my ApplicationPool identity for the service Modify permissions on the /MyService.svc file. 我通过为/MyService.svc文件上的服务修改权限授予我的ApplicationPool标识来解决问题。

I picked up this tip from this post: http://social.msdn.microsoft.com/Forums/eu/adodotnetdataservices/thread/987b5808-d1d3-41a6-be80-206ead679f46 我在这篇文章中提到了这个提示: http//social.msdn.microsoft.com/Forums/eu/adodotnetdataservices/thread/987b5808-d1d3-41a6-be80-206ead679f46

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM