looking for a few good ideas

  amongst the irregular verbiage

ASP.NET and impersonation trouble

So I have this Asp.NET application that needs to run on the WEBSERVER but see files in a directory on FILESERVER out on the net. (The files are, inevitably, Foxpro tables being accessed through OleDb.)

First cut, the OleDbConnection fails to open the data (\\FILESERVER\Sharename\datafolder) with an "invalid path or file name" error. That's because the ASP.NET application is running under the WEBSERVER/aspnet user context which does not have permission to see the network share.

"No problem," we say. "Let's just use the web.config file to tell Asp.NET to run under a context that does have permission to see the share:

    <identity impersonate="true"

This works - except that every time we uploaded a new version of the .aspx files to the webserver, it threw an exception: "Cannot execute a program. The command being executed was [..]\v1.1.4322\csc.exe /noconfig ...". Basically it didn't appear to have rights to run the compiler to do that special ASP.NET on-the-fly compilation of the classes.

Investigation seemed to indicate that it should have the appropriate access rights, but all the same, we couldn't make it work without commenting out the <identity> specification; re-starting the IIS process; then putting it back after the successful compilation so that the network share was visible.

Second cut was to omit the <identity> override, but to bracket the OleDb call with special in-line user impersonation code using Win32 LogonUser() calls. Well that didn't work (and when I find out why, perhaps I'll post about it).

I found a solution to the problem on a web thread posted by shamrox (http://forums.rainbowportal.net/ShowPost.aspx?PostID=5503) which I reproduce here:

Is this error happening when you try to run your project? I guess what I am asking is that it compiles fine but when it goes to the first screen you get this error. IE would never open if it didn't compile.

If it is what I think it has to do with the aspnet_wp. It does some weird stuff. You don't have to restart www to fix it, all you need to do is go to task manager and [terminate the aspnet_wp.exe process]. Don't worry it restarts automatically. That will fix the problem for now. It comes up from time to time so if there is a better way I would like to know too.

Thanks shamrox - this works! Now we can leave the <identity> switch in place in the web.config in order for my web site to "see" the network resources, and when I upload a new version of the aspxs to my web site - it will stick with the exception on the recompile but a restart of the aspnet_wp.exe process will bring it back, no worries.

I still think ASP.NET is the bomb.