简体   繁体   English

在托管应用程序中写入日志

[英]To write logs in hosted application

We have created one C# MVC applicaion. 我们创建了一个C#MVC应用程序。 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". 问题是,当我们使用log4net将日志文件创建到存在于“ ..inetpub / mysite / errorLogs”的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."); 我也尝试过使用System.IO.File.AppendAllText(sFilePath, "test content.");在文件中进行简单编写System.IO.File.AppendAllText(sFilePath, "test content.");

at path "..inetpub/mysite/App_Data/errorLogs". 在路径“ ..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 : 在查看权限时,我们对App_Data文件夹拥有所有权限,但是会引发错误:

Server Error in '/' Application. “ /”应用程序中的服务器错误。

Access to the path '...\\inetpub\\mysite\\App_Data\\Logs\\20151026' is denied. 拒绝访问路径'... \\ inetpub \\ mysite \\ App_Data \\ Logs \\ 20151026'。

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.UnauthorizedAccessException:拒绝访问路径'... \\ inetpub \\ mysite \\ App_Data \\ Logs \\ 20151026'。

ASP.NET is not authorized to access the requested resource. 没有授权ASP.NET访问请求的资源。 Consider granting access rights to the resource to the ASP.NET request identity. 考虑将资源的访问权限授予ASP.NET请求标识。 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. ASP.NET具有一个基本进程标识(在IIS 5上通常为{MACHINE} \\ ASPNET或在IIS 6和IIS 7上为Network Service,在IIS 7.5上通常是配置的应用程序池标识),如果应用程序没有模拟,则使用该标识。 If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 如果应用程序通过进行模拟,则身份将是匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的请求用户。

To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. 要授予ASP.NET对文件的访问权限,请在文件资源管理器中右键单击该文件,选择“属性”,然后选择“安全性”选项卡。 Click "Add" to add the appropriate user or group. 单击“添加”以添加适当的用户或组。 Highlight the ASP.NET account, and check the boxes for the desired access. 突出显示ASP.NET帐户,然后选中所需访问权限的框。

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(). 就我而言,我期望在应用程序池上设置的用户是拥有用File.AppendAllText()编写的文件的用户。

However, it is the user that you Connect As, which is used, if it is set. 但是,如果您设置了Connect As,将使用该用户。

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. 结果,虚拟应用程序编写的任何文件的所有者都是本地用户,称为IUSR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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