从字面上看,每次我运行一个大丑陋的网站项目时,我都会收到一条UnauthorizedAccessException,其中有一条指向DLL的消息,例如Temporary ASP.NET Files\ctheweb\0d76d363\4695c81f\App_Web_vi6bbbpy.dll' is denied.
我然后停止并重新启动项目,它运行正常.我做了一些测试,调试,修复,再次运行,然后再次出错.
我倾向于添加一个预构建命令来清除该目录,但我总是更喜欢用锤子以外的东西来解决问题,至少最初是这样.
在开发期间,当您不断修改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
如果在生产中发生这种情况,请将此添加到web.config.
(滚动到侧面,关键是选择一些\ Other \文件夹而不是默认值.
最后,使用Deployment项目尝试提前预编译所有内容.没有编译意味着没有尝试替换temp文件夹中的内容
或者您可以尝试操作系统诊断并尝试找出哪个进程锁定该文件并终止该进程.当存在更简单的解决方案时,不值得努
在我的情况下,答案是微不足道的 - 从一开始就不是一个错误.对我来说,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