【问题标题】:Write to a Logfile from ASP.NET website running under II8.5从在 II8.5 下运行的 ASP.NET 网站写入日志文件
【发布时间】: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

【问题讨论】:

    标签: asp.net iis logging


    【解决方案1】:

    请将用户组添加到您的日志文件夹并授予该组完全权限(读/写)。

    要进一步了解 w3wp 使用了哪个特定用户,您可以按照here 的说明使用进程监视器

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

    1. 拒绝访问时过滤
    2. 没有拒绝访问,所以过滤 w3wp.exe
    3. 寻找对 401-3.htm 的访问权限
    4. 查看 401-3.htm 之前的条目以确定上次访问的文件
    5. 根据成功的 QuerySecurityFile 操作检查最后访问的文件(在本例中为 asp.dll)的权限

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      相关资源
      最近更新 更多