频繁访问被拒绝临时ASP.NET文件

Pro*_*ofK 14 asp.net visual-studio-2008

从字面上看,每次我运行一个大丑陋的网站项目时,我都会收到一条UnauthorizedAccessException,其中有一条指向DLL的消息,例如Temporary ASP.NET Files\ctheweb\0d76d363\4695c81f\App_Web_vi6bbbpy.dll' is denied. 我然后停止并重新启动项目,它运行正常.我做了一些测试,调试,修复,再次运行,然后再次出错.

我倾向于添加一个预构建命令来清除该目录,但我总是更喜欢用锤子以外的东西来解决问题,至少最初是这样.

Mat*_*tin 11

在开发期间,当您不断修改aspx页面时,会发生这种情况,ASP.NET正在尝试编译,而VS正在尝试编译,而ASP.NET正在尝试执行这些文件.此外,有时重置IIS时锁会消失.

iisreset /stop
del "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\*.*"  /Q /F /S
del “C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*” /Q /F /S
iisreset /start
Run Code Online (Sandbox Code Playgroud)

如果在生产中发生这种情况,请将此添加到web.config.

<compilation tempDirectory = “C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\Other\” />
Run Code Online (Sandbox Code Playgroud)

(滚动到侧面,关键是选择一些\ Other \文件夹而不是默认值.

最后,使用Deployment项目尝试提前预编译所有内容.没有编译意味着没有尝试替换temp文件夹中的内容

或者您可以尝试操作系统诊断并尝试找出哪个进程锁定该文件并终止该进程.当存在更简单的解决方案时,不值得努

  • 请有人解释为什么这篇文章被否决了?在没有贡献的情况下简单地拒绝投票是没有建设性的,而且是粗鲁的。 (2认同)

Oha*_*der 11

在我的情况下,答案是微不足道的 - 从一开始就不是一个错误.对我来说,ASP.NET实际上每次启动我的Web应用程序时都会抛出它,我只是忘记了"在所有异常中断"设置(从另一个调试会话).我检查了一切,一切正常.

作为参考,这是堆栈跟踪:

>   mscorlib.dll!System.IO.__Error.WinIOError(int errorCode, string maybeFullPath)  Unknown
    mscorlib.dll!System.IO.FileStream.Init(string path, System.IO.FileMode mode, System.IO.FileAccess access, int rights, bool useRights, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost)    Unknown
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, string msgPath, bool bFromProxy)  Unknown
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode)  Unknown
    System.Web.dll!System.Web.UI.Util.HasWriteAccessToDirectory(string dir) Unknown
    System.Web.dll!System.Web.HttpRuntime.SetUpCodegenDirectory(System.Web.Configuration.CompilationSection compilationSection) Unknown
    System.Web.dll!System.Web.HttpRuntime.HostingInit(System.Web.Hosting.HostingEnvironmentFlags hostingFlags, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException) Unknown
    System.Web.dll!System.Web.HttpRuntime.InitializeHostingFeatures(System.Web.Hosting.HostingEnvironmentFlags hostingFlags, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException)   Unknown
    System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel, System.Exception appDomainCreationException) Unknown
    System.Web.dll!System.Web.Hosting.HostingEnvironment.Initialize(System.Web.Hosting.ApplicationManager appManager, System.Web.Hosting.IApplicationHost appHost, System.Web.Configuration.IConfigMapPathFactory configMapPathFactory, System.Web.Hosting.HostingEnvironmentParameters hostingParameters, System.Security.Policy.PolicyLevel policyLevel)  Unknown
    [AppDomain (DefaultDomain, #1) -> AppDomain (/LM/W3SVC/4/ROOT-1-130624548490751465, #2)]  
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters) Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.GetAppDomainWithHostingEnvironment(string appId, System.Web.Hosting.IApplicationHost appHost, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)   Unknown
    System.Web.dll!System.Web.Hosting.ApplicationManager.CreateObjectInternal(string appId, System.Type type, System.Web.Hosting.IApplicationHost appHost, bool failIfExists, System.Web.Hosting.HostingEnvironmentParameters hostingParameters)    Unknown
    System.Web.dll!System.Web.Hosting.ProcessHost.StartApplication(string appId, string appPath, out object runtimeInterface)   Unknown
Run Code Online (Sandbox Code Playgroud)


Ste*_*per 5

如果它由某些外部进程(如病毒扫描程序或搜索索引器)引起的锁定,那么您可以尝试使用 Windows 权限来锁定其他用户和进程读取文件的权限。默认情况下,Temporary ASP.NET Files目录可供用户、管理员、IIS_USR、SYSTEM 和 TrustedInstaller 使用——也就是说,几乎所有人都可以使用。

试试 MatthewMartin 对不同编译文件夹的建议;

<compilation tempDirectory = “C:\LimitedPermissionCompilationDir\” />
Run Code Online (Sandbox Code Playgroud)

然后限制 LimitedPermissionCompilationDir文件夹为仅需要权限的用户和组——例如,如果您在 IIS 上运行,则为 IIS_USR,或者如果您正在为基于文件的 Web 服务器进行编译,则为您自己的帐户。

无论如何,这是一种相对安全的尝试方式,因为您无需担心会影响您正在运行的站点以外的任何内容。