简体   繁体   English

WCF:尝试写入文本文件/日志,获取UnauthorizedAccessException吗?

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

I'd like my service to write to a log file. 我希望我的服务写入日志文件。 How can I get "access" to do this? 如何获得“访问权限”来执行此操作? I'm just running visual studio / asp.net... not really deployed or nothing. 我只是在运行Visual Studio / asp.net ...没有真正部署或什么也没有。

To write to the log file, make sure that the identity running your web application has write access to the log directory. 要写入日志文件,请确保运行Web应用程序的身份具有对日志目录的写访问权

IIS7: You can find the identity in the IIS management console. IIS7:您可以在IIS管理控制台中找到身份。 Select the application pool that your web application is using. 选择您的Web应用程序正在使用的应用程序池。 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. IIS6:与IIS7相同,只是右键单击应用程序池并选择属性。 The properties window of IIS6 will have an Identity tab. IIS6的属性窗口将具有“身份”选项卡。

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 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. 除了检查文件上的只读标志外,还必须考虑要写入的文件所在的目录。例如,当您在Windows Vista和Windows 7中写入文件时,通常不喜欢它。程序文件目录和程序文件的任何子目录。 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. 在这种情况下,它变成了权限问题,而不是编程问题,您将必须以提升的权限(管理员权限)运行应用程序和/或更改目录中的安全权限,或者更改要尝试写入文本文件的目录/登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在C#中写入文本文件时出现UnauthorizedAccessException - UnauthorizedAccessException when trying to write to text file in C# Windows Service写入文件-UnauthorizedAccessException - Windows Service write to a file - UnauthorizedAccessException UnauthorizedAccessException-尝试将JSON序列化为文件 - UnauthorizedAccessException - Trying to serialize JSON to a file 无法写入Registry Key,获取UnauthorizedAccessException - Cannot write to Registry Key, getting UnauthorizedAccessException 多线程写入WCF请求中的文本文件? - Multithread Write into Text File in WCF request? 在 File.Create 上获取 System.UnauthorizedAccessException - getting System.UnauthorizedAccessException on File.Create 如何将文本写入log4net文件 - How to write text into log4net file 尝试从网络获取文件时获取System.UnauthorizedAccessException - Getting System.UnauthorizedAccessException when trying to fetch files from network 尝试从 .NET 中的 SQL Server 提取图像,出现 UnauthorizedAccessException - Trying to extract image from SQL Server in .NET, getting UnauthorizedAccessException 使用log4net将原始文本写入日志文件 - Write raw text in log file using log4net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM