开发者

WCF: Trying to write to a text file / log, getting UnauthorizedAccessException?

开发者 https://www.devze.com 2023-01-28 15:41 出处:网络
I\'d like my service to write to a log file. Ho开发者_Go百科w can I get \"access\" to do this? I\'m just running visual studio / asp.net... not really deployed or nothing.To write to the log file, mak

I'd like my service to write to a log file. Ho开发者_Go百科w can I get "access" to do this? I'm just running visual studio / asp.net... not really deployed or nothing.


To write to the log file, make sure that the identity running your web application has write access to the log directory.

IIS7: You can find the identity in the IIS management console. Select the application pool that your web application is using. Click on Advanced Settings. In the properties window, look for the identity field. It may say Network Service. This is the account that needs write permission to your log output folder.

IIS6: Same as IIS7 except right click on the app pool and select properties. The properties window of IIS6 will have an Identity tab.

If you already have a log file in this directory, try deleting it and letting the framework create it.

Hope this helps.


Check the readonly flag on the log file, and clear it if it is set.

http://www.eggheadcafe.com/software/aspnet/32181030/unauthorizedaccessexception-in-debug-mode-only.aspx


In addition to checking of the readonly flag on the file you also must take into account what directory the file you are trying to write to is in. Windows Vista and Windows 7 for example typically do not like it when you write to a file in the program files directory and any child directory of program files. In this case it becomes a permissions issue not a programming issue, you would have to run the application with elevated permissions (administrator privileges) and / or change the security permissions in the directory, or change the directory you are trying to write the text file / log to.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号