【发布时间】:2016-09-10 17:38:56
【问题描述】:
我有一个假设写入日志文件的 ASP.NET 应用程序。日志文件位于网站目录中的文件夹下(即 E:\Parentfolder\Appfolder\Logs\MyAppLog.Log.
但是,我收到以下错误。我相信这是一个权限错误,我已授予 IUSER、网络服务、SYSTEM 对文件夹和日志文件的完全权限,但没有运气。我必须在 IIS 或 web.config 中做任何特别的事情吗?
后面的代码是C#,网站部署在IIS 8.5 (8.5.9600.16384)上。
请帮忙。
错误:
Access to the path 'E:\Parentfolder\Appfolder\Logs\MyAppLog.Log' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'E:\Parentfolder\Appfolder\Logs\PassLog.Log' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[UnauthorizedAccessException: Access to the path 'E:\apps\PASS-Portal\Logs\PassLog.Log' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +216
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1430
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +211
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) +210
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) +22
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) +17
System.IO.File.AppendAllLines(String path, IEnumerable`1 contents) +168
PASS_DP_WA_001.PassLog.Log(String message) in C:\Ufolder\ffodler\Documents\myAppFolder\from-A\MyApp_DP_WA_001\MyApp_DP_WA_001\PassLog.cs:119
PASS_DP_WA_001.JIRAManager.PostUserToJIRA() in C:\Ufolder\ffodler\Documents\myAppFolder\from-A\MyApp_DP_WA_001\MyApp_DP_WA_001\XManager.cs:48
【问题讨论】: