views:

63

answers:

2

I have a website that I publish in Visual Studio 2008 and then send off to other people. One of the pages needs to alter a few configuration files, so an action is executed using WindowsImpersonationContext inside a class library referenced by the website.

protected void WithImpersonation(ExecuteUnderImpersonation action)
{
    using(WindowsImpersonationContext context = Request.LogonUserIdentity.Impersonate())
    {
        action();
    }
}

However when someone else tries to submit this page, it throws an error that it was

Unable to save config to file 'C:\Inetpub\wwwroot\SomeWebsite\web.config'.

Looking at the StackTrace I see this entry:

at SomeClassLibrary.SomeClass.WithImpersonation(ExecuteUnderImpersonation action) in FILEPATH FROM MY MACHINE:line 23

This appears to be happening on only one specific page, even though multiple pages call this same method.

If I've published the website (in Updatable mode) to the PrecompiledWeb folder, and released it with the appropriate references in the bin directory, why does it look for the class on my machine? The error doesn't even make sense, if its looking for a file that doesn't exist on their server, shouldn't they be getting a much different error?

I took the same website and put it up on one of my servers connected to the domain. If I tried running that same page from the server logged in as myself, or on my machine, I don't receive this error.

A coworker has said before that they also receive this error sometimes, but that it eventually goes away. We can't pinpoint the cause of the issue, but if the same website were to be checked out of SVN on someone elses computer, published, and then sent off, this error doesn't happen at all.

Any ideas as to what is going on?

+2  A: 

That's part of the Program Debug Database (.PDB file) as far as I know. Well, the part where you think it's referencing your machine that is.

You really should use a build server. ;-) But that's another topic.

The reason that error happens is because presumably the other users do not have the correct ACL's set to save to the web folder.

Wim Hollebrandse
We do use build servers, but this was sort of a "special circumstance" that goes beyond me as a developer. I didn't check to see if the .pdb files were being included in the bin folder, but it is possible. I thought I had build it in release mode, but I might be wrong.
Brandon
There may still be entry points for original source file in the assembly as well - PDB may hook into those and then provide more detailed info.
Wim Hollebrandse
You appear to be correct, pdb files were deployed with the published website. I know very little about pdb files aside from the fact they help me debug, so you just saved me a lot of wasted time. Thanks!
Brandon
No probs, but that will not solve the actual error you are seeing which has to do with permissions and not being able to save.
Wim Hollebrandse
@Wim, but actually, when we were trying to figure out the cause, the config error pointed towards permissions, so we pretty much gave everyone full control to the entire website (its a test server, so we didn't care) and it still showed up. Shouldn't that have fixed the error then?
Brandon
Also - PDB files are deployed nowadays (since 2005) when building in Release mode. Just that the assembly code is optimized for Release.
Wim Hollebrandse
Brandon, I suggest you open a different question in that case, with another title and details that relate to the error you're still seeing.
Wim Hollebrandse
@Wim, sure, makes sense. I'll poke around a bit more before doing so. Thanks for your help.
Brandon
Also - make sure you disable 'Anonymous' access in IIS (Security tab) and tick Windows Integrated authentication.
Wim Hollebrandse
+1  A: 

It's just the path to the source file when the application was compiled. I'm sure that your error isn't related to it. I suspect that your problem is that, while you may have permission to modify the file, most users don't. Check the permissions on the file/directory to see if you need to open it up. Perhaps the reason that it doesn't always happen is that the files only need to be updated once and eventually someone with the right credentials accesses it and it's then fixed for everyone.

tvanfosson