Server.Map Path Failure
This is one of those posts that exists to remind myself of my own stupidity.
So, this is the code I was writing:
string pathToFile = Server.MapPath(ConfigurationManager.AppSettings.Get(”SmartCardMaker_PathToPdfForm”));
FileStream _stream = new FileStream(pathToFile,FileMode.Open,FileAccess.ReadWrite);
Seems pretty straightforward, but for the life of me I couldn’t figure out why the code would run locally and on the dev server, but not on the staging environment, where I was getting a SecurityAccessException. Here’s the catch;
I’m using a WebDeployment Project on this gig (like I nearly always do) with sections of web.config being overwritten based on build configuration. I forgot to add the key for the path to the replacement files and the call to Server.MapPath() was returning the path to the folder of the page that was making the call.
I didn’t find it on the dev box, because I was using the “publish” function rather than the deployment script, so the same web.config file was being used locally and on dev.
It would have been nice if the call to ConfigurationManager.AppSettings.Get had thrown an exception on the missing key item rather than failing silently, but it would have been smarter for me to make the changes to web.config replacement files in the first place.
Some days, I’m a real dummy.

Leave a Reply