Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
865 views
in Technique[技术] by (71.8m points)

c# - Wrong path returned by Environment.GetFolderPath(Environment.SpecialFolder.ApplicationFolder) under IIS6 WebService

On my test machine running (Windows XP, IIS5.1) the following code executed within a C# .NET WebService (.SVC) under a custom process identity (using machine.config to specify the user)

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

correctly returns

c:Documents and SettingsmyUserNameApplication Data

However, on (Terminal Services) Windows 2003 machine running IIS6 and executing the same code but now using ApplicationPool to specify the same process identity the method returns:

c:Documents and SettingsDefault UserApplication Data

Things I have checked while running on the Win2003/IIS6 machine:

  1. myUserName belongs to the group IIS_WPG (even tried Admin)
  2. a call to Environment.UserName correctly returns myUserName
  3. a call to Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); also returns a 'Default User' path, likewise with DesktopDirectory
  4. logged on as myUserName and ensured that C:Documents and settingsmyUserName exists
  5. running the exact same code in a .net application on the Windows 2003 box, this works and returns the correct path.

I am baffled, it only occurs when runing under IIS6. It is almost like it thinks that the call is coming from Network Service or Local System users and it is not checking the Identity running the Application Pool.

Incidentally when I look at Procmon and watch a C++ application that is called from the webservice it has no such problem reading and writing to C:Documents and settingsmyUserNameApplicatonData, it does not seem to have a problem, perhaps it builds the path differently.

I am starting to think this might be a bug in .NET??

Thanks.

Tom Deloford

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solved. Apparently this is 'by design' because IIS6 does not load user profile settings.

Microsoft advised me to upgrade to IIS7 or call LoadUserProfile first, I wonder what possessed them to change that functionality from IIS5.1.

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/890fa85a-b11a-4fbe-a333-cbe69abd72a7

Anyway lesson learned, don't assume functionality hasn't been removed and always test with the same application server even if annoys the IT department!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...