2009-05-27 42 views
13

字面上我每次運行一個大的醜陋的網站項目,我得到一個UnauthorizedAccessException,並帶有一條指向DLL的消息,例如, Temporary ASP.NET Files\ctheweb\0d76d363\4695c81f\App_Web_vi6bbbpy.dll' is denied.然後停止並重新啓動項目,並且運行良好。我做了一些測試,調試,修復,再次運行,並再次得到錯誤。頻繁訪問被拒絕臨時ASP.NET文件

我傾向於添加一個預生成命令來清除那個目錄,但我總是喜歡用錘子以外的其他東西來解決問題,至少在最初的時候。

+0

我一直在這個星期收到此錯誤也。但是,它只是在我的應用程序池在64位機器上切換到32位後纔開始。這也是你的情況嗎? – 2011-01-28 14:57:18

回答

10

在開發過程中,當您不斷修改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中。

<compilation tempDirectory = 「C:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\Other\」 /> 

(滾動到一邊,關鍵是要挑選一些\其它\文件夾不是默認的。

最後,使用部署的項目,試圖提前預編譯的一切。沒有編譯意味着沒有企圖取代Temp文件夾東西

或者你可以嘗試OS診斷和嘗試找出哪個進程對文件的鎖定並殺死該進程。不值得時,更容易的解決方案存在。

+1

請有人可以解釋爲什麼這個職位被拒絕?簡單地沒有貢獻的投票並不具有建設性和簡單的粗魯。 – ProfK 2009-05-28 17:15:39

+0

我並不是要捍衛隨機投票,但你的問題是你不想用錘子,而這是我給你的大錘。因爲這是一個開發箱,腳本運行速度很快(不像最糟糕的錘子,重新啓動),這對我來說似乎很合適。 – MatthewMartin 2009-05-28 17:22:17

0

確保您沒有像「Windows桌面搜索」索引該文件夾的進程。

0

這聽起來像你有東西持有該文件的開放式句柄;您可以使用Filemon或某些類似的工具來追蹤它,看看它握着打開的手柄的過程。

1

我有過類似的問題過去由於工作站的防病毒程序在「錯誤」時間訪問文件。您可以使用另一個工具來確定打開文件的內容:Process Explorer(推薦用於您的個人武器庫,坦率地說,即使此文件無效)。

4

如果它是由某個外部進程(如病毒掃描程序或搜索索引器)引起的鎖定,則可以嘗試使用Windows權限來鎖定其他用戶的權限以及進程讀取文件的權限。默認情況下,Temporary ASP.NET Files目錄可供用戶,管理員,IIS_USR,SYSTEM和TrustedInstaller使用 - 也就是說,幾乎每個人都可以使用該目錄。

試用MatthewMartin對不同編譯文件夾的建議;

<compilation tempDirectory = 「C:\LimitedPermissionCompilationDir\」 /> 

然後限制LimitedPermissionCompilationDir文件夾,只是用戶和誰需要權限組 - 比如說,IIS_USR如果你在IIS,或您自己的帳戶下運行,如果要編譯支持基於文件的網絡服務器。

無論如何,這是一個相對安全的嘗試方法,因爲您不必擔心影響您正在運行的網站以外的任何其他方面。

1

我在我的web.config中爲另一個用戶使用ipersonation時發現了這個,並且用戶沒有權限。衛生署!

9

就我而言,答案很簡單 - 從一開始就不是錯誤。對我而言,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