Impersonation in .Net
I’ve been struggling to get a project another developer has been working on to build on my machine, the main problem has been that the files within the App_Code folder did not recognise any of the dll’s or their class names and so other than the basic System and Microsoft namespaces I could not access anything. After quite a bit of frustration I have finally tracked down the issue…
The project uses windows impersonation to enable access to certain features within a CMS system this has been set in the web.config. It was set to use another user account and for the purposes of publishing the site I did not see any reason to change it. Oh what a fool I am. It seems that Visual studio actually uses these credentials to access files on the system and as the impersonated user has never logged onto my laptop (or perhaps his password has changed) VS would not allow the App_Code folder files to access the dll’s. Changing the impersonation settings to my own resolved this issue. So the conclusion is if you are using impersonation ensure the account is valid on the machine you are developing on and not just the one you run it on.
Alternatively to avoid this problem altogether DON’T user impersonation or use a generic network / domain account which is documented and shared with all other developers. The main reason for this is that if you use a personal account then it could be easily hijacked and series damaged could be caused because of your user privileges not to mention that your password will be visible in the web.config!

