Could not load file or assembly or one of its dependencies. Access is denied. The issue is random, but after it happens once, it continues

.net-assemblyasp.net

I have found plenty of information out there about this error: 'ERROR: Could not load file or assembly '*.dll' or one of its dependencies. Access is denied.’
But i haven't found answer specific to my scenario.
My site is deploy on 6 different production servers, only on one server i am facing this issue. The issue is random, but after it happens once, it continues until the site is recompile by done a small modification in web.config file(i know trick, after modification in web.config recompile the web application) and site on that server start working.
Yesterday, issue was reproducing after one month period of working.
We can't afford this issue on production.
Issue detail:

Server Error in '/' Application.
____________________________________
Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:

[FileLoadException: Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.]
…DbImpl.Event.TTCEventController.GetEventFields(Int32 eventId) +0
WebSuite.SportChannel.ModelImpl.TTCModelController.AddEventFieldList(XmlElement eventNode, ITTCEventController ctrl, Int32 eventId, PlayerType stupidType) in …root\SportChannel\ModelImpl\Ttc\TTCModelController.cs:171
…ModelImpl.TTCModelController.GetLatestFourTourSchedulesXml() in …root\SportChannel\ModelImpl\Ttc\TTCModelController.cs:283
…WebRoot.UserControls.HeadlinesTab.Page_Load(Object sender, EventArgs e) +491
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
____________________________________

Version Information: Microsoft .NET Framework Version:2.0.50727.5446; ASP.NET Version:2.0.50727.5420

Best Answer

For my scenario, I found that there was a identity node in the web.config file.

<identity impersonate="true" userName="blah" password="blah">

When I removed the userName and password parameters from node, it started working.

Another option might be that you need to make sure that the specified userName has access to work with those "Temporary ASP.NET Files" folders found in the various C:\Windows\Microsoft.NET\Framework{version} folders.

Hoping this helps someone else out!