Got a "401 - Unauthorized" when trying my WCF Data service on IIS
I developed a WCF Data Service, which runs fine, I can do every operation I want through.
I developed a small c# client which tests all functions: adding, removing, modifying, retrieving data.
Everything works fine on my visual studio server, but once I'm on the IIS Server:
- I can add/retrieve data
- I cannot edit data
When I try to edit data I get this error:
System.Data.Services.Client.DataServiceRequestException was unhandled
Message=Une erreur s'est produite lors du traitement de cette requête. Source=System.Data.Services.Client StackTrace: à System.Data.Services.Client.DataServiceContext.SaveResult.HandleBatchResponse() à System.Data.Services.Client.DataServiceContext.SaveResult.EndRequest() à System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) à System.Data.Services.Client.DataServiceContext.SaveChanges() à WSTester.Program.ModifySomeThings(Entities entities) dans D:\Workspace\10067.GfK Telecontrol.TOM\Release\V3.1\WSTester\Program.cs:ligne 90 à WSTester.Program.Main(String[] args) dans D:\Workspace\10067.GfK Telecontrol.TOM\Release\V3.1\WSTester\Program.cs:ligne 23 à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart() InnerException: System.Data.Services.Client.DataServiceClientException Message= Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 401 - Unauthorized: Access is denied due to invalid credentials..content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} -->
Server Error
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directo开发者_运维技巧ry or page using the credentials that you supplied.
Source=System.Data.Services.Client
StatusCode=401 StackTrace: à System.Data.Services.Client.DataServiceContext.SaveResult.d__1e.MoveNext() InnerException:
Which is strange, because I've all rights in my WCF Data service(and it works with visual studio), and I'm in anonymous mode in IIS, so I should have all rights to runs this query. IIS_USR has FULL CONTROL on the web folder, so I really don't see what can be the problem
I just fixed mine by giving "full control" to the "IUSR" account for the WCF folder. That's all I did and it worked.
Try using the impersonation features of the app pool to user that has permissions. I have had many problems in the past using the default AppPoolIdentity
features of IIS 7 and generally assign it to either a user setup for this very purpose or set it to use networkservice.
It is most likely that the pool doesn't have the proper permissions to execute properly.
I made it run with a custom user and now it works, so if you have this problem, you can try the following on your IIS Server:
- Create a windows user;
- Give it read/write/modify/execute/... rights on your WCF data service folder;
- Create a new app pool with .NET 4, integrated mode, and this user;
- On the authentication of the website, enable only the anonymous mode, and set the user to "Application Pool identity".
精彩评论