从II8.5

时间:2016-09-09 23:21:18

标签: asp.net iis logging

我所有的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

1 个答案:

答案 0 :(得分:1)

请将Users组添加到您的logs文件夹,并为该组授予完全权限(读/写)。

要进一步了解w3wp使用的特定用户,您可以按照here所述使用流程监控器

再现问题时捕获进程监视器日志

  1. 过滤拒绝访问
  2. 无法拒绝访问,因此请过滤w3wp.exe
  3. 寻找401-3.htm
  4. 的访问权限
  5. 查看401-3.htm之前的条目以确定最后访问的文件
  6. 根据成功的QuerySecurityFile操作检查访问的最后一个文件的权限(在本例中为asp.dll)