简体   繁体   中英

To write logs in hosted application

We have created one C# MVC applicaion. We have hosted this website successfully and we are able to run correctly. The problem is that when we create logs file using log4net into our errorLogs folder that exist at "..inetpub/mysite/errorLogs". But it didnt allow to write the files there.

Also I have tried with simple writing in file using : System.IO.File.AppendAllText(sFilePath, "test content.");

at path "..inetpub/mysite/App_Data/errorLogs".

But nothing is happening. On looking the permission, we have all permission on App_Data folder, but it throw error :

Server Error in '/' Application.

Access to the path '...\\inetpub\\mysite\\App_Data\\Logs\\20151026' 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 '...\\inetpub\\mysite\\App_Data\\Logs\\20151026' 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 , 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.

Is there another any way to write logging for my website?

尝试将IIS_IUSRS添加到带有日志的权限文件夹中。

In my case, I was expecting the user that was set on the application pool to be the user that would own the file written with File.AppendAllText().

However, it is the user that you Connect As, which is used, if it is set.

In my case, the main website was connecting as a particular user and the same user was on the application pool, but I had a virtual application that was using the same application pool, but was connecting as Pass Through Authentication. As a result, the owner of any files written by the virtual application was a local user called IUSR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM