0

All I have an ASP.NET application that suppose to write to a logfile. The logfile is located under a folder within the website directory (i.e. E:\Parentfolder\Appfolder\Logs\MyAppLog.Log.

However, I'm getting the error below. I believe it's a permission error and I have given IUSER, Network Service, SYSTEM full permissions on the folders and logfile, yet no luck. Do I have to do anything special in IIS or within web.config?

The code behind is C# and the website is deployed on IIS 8.5 (8.5.9600.16384).

Please help.

Error:

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
0

1 Answer 1

1

Please add Users group to your logs folder and give that group full permission (read/write).

To further find out which specific user is used by w3wp you can use process monitor as explained here

Capture Process Monitor log while reproducing issue

  1. Filter on Access Denied
  2. No Access Denied, so filter on w3wp.exe
  3. Look for access to 401-3.htm
  4. Review entries before the 401-3.htm to determine what file was accessed last
  5. Check permissions based on successful QuerySecurityFile operation for last file accessed (in this case was asp.dll)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.