Problem with impersonating a specific user in WCF service
- by aJ
I am having a WCF service hosted in IIS on WindowsServer 2008. This service needs to write to a shared folder present on another machine(Windows XP). The shared folder has write permissions for a particular user say "X" which is present on both the machines .i.e on the server where the service is running as well as the machine where the shared folder is present.
The service runs under the NETWORK SERVICE account. For the service to access the shared folder I have added code to impersonate the user "X"in the service so that it gets the permission to write to the shared folder.
Since I want to impersonate user "X" only when I run a particular section of code I have used the sample code.
Even after the impersonation the service fails to write to the shared folder sometimes. It works sporadically.
Whereas if I add tag in the Web.config file it works perfectly fine.
<identity impersonate="true" userName="accountname" password="password" />
But the above is not desirable since it impersonates a specific user for all the requests. What I need is to impersonate a specific user only when I run a particular section of code.
Also, the impersonation code works absolutely fine when the shared folder is present on another WindowsServer 2008.
Could anyone give me ideas on what's going wrong here.