在 IIS6 上运行的 ASP.NET 站点拒绝 AppDomain 卷影复制文件访问
我在将 AppDomains 的卷影复制功能与 IIS 下运行的 ASP.NET 网站结合使用时遇到一些问题。问题在于,由于权限不足,IIS 用户无法读取或执行卷影复制的文件。
当执行新 AppDomain 中的代码时(通过 DoCallBack 的回调方法),我收到以下错误消息:
System.IO.FileLoadException:无法加载文件或程序集“My.Namespace.AssemblyName,Version=0.0.3.2231,Culture=neutral,PublicKeyToken=null”或其依赖项之一。访问被拒绝。
融合日志:
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running under executable c:\windows\system32\inetsrv\w3wp.exe --- A detailed error log follows. === Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = My.Namespace.AssemblyName, Version=0.0.3.2231, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Inetpub/wwwroot/Web Suite/Widgets LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file: \\?\C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet.config LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Inetpub/wwwroot/Web Suite/Widgets/My.Namespace.AssemblyName.DLL. ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.
我已经做了什么:
我已授予用户“NETWORK SERVICE”对“C:/Inetpub/wwwroot/Web Suite/Widgets”文件夹的读取和执行权限。
当我关闭卷影复制功能时,一切正常。
即使在我的本地计算机上使用 Visual Studio 2008,它也可以正常运行。
授予 Widgets 文件夹中的所有文件(而不是文件夹本身)读取和执行权限并不能解决问题。
我认为这与 ASP.NET 临时文件夹的权限有关:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\web suite
该文件夹、其所有子文件夹以及其中的文件均已读取并已读取&用户“NETWORK SERVICE”的执行权限。所以这也不是问题。
简而言之:
为什么我的网站(在 IIS6 下运行)无法访问新 AppDomain 的卷影复制文件?
I have some trouble with the shadow copy feature of AppDomains in combination with a ASP.NET website running under IIS. The problem is that the shadow copied files can not be read or executed by the IIS user because of insufficient permissions.
I get the following error message when the code in the new AppDomain is executed (through a callback method via DoCallBack):
System.IO.FileLoadException: Could not load file or assembly 'My.Namespace.AssemblyName, Version=0.0.3.2231, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.
Fusion log:
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll Running under executable c:\windows\system32\inetsrv\w3wp.exe --- A detailed error log follows. === Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = My.Namespace.AssemblyName, Version=0.0.3.2231, Culture=neutral, PublicKeyToken=null (Fully-specified) LOG: Appbase = file:///C:/Inetpub/wwwroot/Web Suite/Widgets LOG: Initial PrivatePath = NULL Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file: \\?\C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet.config LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Inetpub/wwwroot/Web Suite/Widgets/My.Namespace.AssemblyName.DLL. ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.
What I have already done:
I have granted the 'C:/Inetpub/wwwroot/Web Suite/Widgets' folder read and execution permission for the user 'NETWORK SERVICE'.
When I turn off the shadow copying feature, everything goes fine.
Even on my local computer under Visual Studio 2008 it runs without any problem.
Granting all files (instead of the folder itself) in the Widgets folder read and execution permission does not solve the problem.
I thought it have to do with the permissions on the ASP.NET temporary files folder:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\web suite
This folder, all its sub folders and the files within them have read and read & execute permissions for the user 'NETWORK SERVICE'. So that's not the problem either.
To be short:
Why can't my site (running under IIS6) access the shadow copied files of the new AppDomain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题的原因是CachePath默认值。如果 AppPool 在网络服务下运行,则使用 DefaultUser 临时文件夹位置(我不知道为什么)。但网络服务无权访问该文件夹,这就是异常的原因。解决方案是显式设置 CachePath。例如,我们可以使用 ASP.NET AppPool 缓存路径:
The reason of the problem is CachePath default value. If an AppPool is run under network service, DefaultUser temp folder location is used (I don't know why). But Network Service doesn't have access to the folder and it's the reason of the exception. The solution is to set CachePath explicitly. For example, we can use ASP.NET AppPool cache path:
尝试使用 - 运行 aspnet_regiis ga 选项如下:
aspnet_regiis -ga MachineName\AccountName
其中 MachineName\AccountName 是应用程序池的标识。
Try running aspnet_regiis with the -ga option like this:
aspnet_regiis -ga MachineName\AccountName
where MachineName\AccountName are the identity of your application pool.