错误信息如下:
“/”应用程序中的服务器错误。--------------------------------------------------------------------------------未能加载文件或程序集“XXXXDBHelper,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”或它的某一个依赖项。拒绝访问。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息: System.IO.FileLoadException: 未能加载文件或程序集“XXXXDBHelper,PublicKeyToken=null”或它的某一个依赖项。拒绝访问。源错误:执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 程序集加载跟踪: 下列信息有助于确定程序集“XXXXDBHelper,PublicKeyToken=null”未能加载的原因。警告: 程序集绑定日志记录被关闭。要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。注意: 会有一些与程序集绑定失败日志记录关联的性能损失。要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。堆栈跟踪:
[FileLoadException: 未能加载文件或程序集“XXXXDBHelper,PublicKeyToken=null”或它的某一个依赖项。拒绝访问。] XXXXWEB.MODULE.BAS.Left.Page_Load(Object sender,EventArgs e) +0 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +3178--------------------------------------------------------------------------------版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.17929
错误描述如下:
环境:开发工具:VS2012数据库:ORACLE 11G语言:C#.NET发布服务器:IISIIS发布C#.NET工程后,如果长时间(大概30分钟吧)不操作页面,再次操作需要连接数据库的页面,就会报这个错误。网上也搜索了很多资料,基本上都是说缺少dll、缺少文件等,但是我比对了没问题和出问题后的所有文件,发现都是一样的,所以排除了缺失文件的可能。断断续续的两天时间都是用来解决这个问题,一度还怀疑是不是服务器中途插拔过一次硬盘造成的。最后突然想到了web.config,因为我的工程是demo工程,是之前的另外个项目搬过来临时用的,web.config是比较乱的,所以我另外建了一个解决方案,新建一个测试工程,新建工程的web.config非常单纯,就一个.NET版本的定义,我加上了数据库的连接字串,再把所有的代码复制进去。发布,试用,发现没有异常,于是我把新建测试工程的web.config的内容复制到正式工程中,然后发布,试用两天,隔了一个夜晚,没有出现这个问题,哦。。。。中午解决了。特意写出来,如果大家遇到这个问题也可以有个排除问题的店。虽然我问题解决了,但是我还没有找出来是哪个配置出的问题,有时间了再排除测试下,如果哪位大神能看出来,也帮我留言指出,我测试下,谢谢。
原web.config内容如下:
<?xml version="1.0" encoding="UTF-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <appSettings> <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" /> </appSettings> <connectionStrings> <add name="constr" connectionString="Provider=sqlOLEDB;Data Source=.;Initial Catalog=CzceTestSuite;User ID=sa;Password=sa13456;" /> <add name="conorclstr" connectionString="Provider=OraOLEDB.Oracle.1;User ID=xxxx;Password=1234qwer;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))" /> <add name="conorclserverstr" connectionString="Provider=OraOLEDB.Oracle.1;User ID=xxxx;Password=XXXX13579;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.123)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))" /> </connectionStrings> <!-- 有关 .NET 4.5 的 web.config 更改的说明,请参见 http://go.microsoft.com/fwlink/?LinkId=235367。 可在 <httpRuntime> 标记上设置以下特性。 <system.Web> <httpRuntime targetFramework="4.5"/> </system.Web> --> <system.web> <compilation targetFramework="4.5"> <assemblies> <add assembly="System.Web.DataVisualization,Version=4.0.0.0,PublicKeyToken=31BF3856AD364E35" /> <add assembly="System,PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Drawing,PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Web,PublicKeyToken=B03F5F7F11D50A3A" /> <add assembly="System.Xml,PublicKeyToken=B77A5C561934E089" /> <add assembly="System.Data,PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <membership> <providers> <clear /> <add name="AspNetsqlMembershipProvider" type="System.Web.Security.sqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minrequiredPasswordLength="6" minrequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear /> <add name="AspNetsqlProfileProvider" type="System.Web.Profile.sqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> </providers> </profile> <roleManager enabled="false"> <providers> <clear /> <add name="AspNetsqlRoleProvider" type="System.Web.Security.sqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> <pages controlRenderingCompatibilityVersion="4.0"> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions,Version=3.5.0.0,PublicKeyToken=31BF3856AD364E35" /> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions,PublicKeyToken=31BF3856AD364E35" /> <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization,PublicKeyToken=31bf3856ad364e35" /> </controls> </pages> <httpHandlers> <remove path="*.asmx" verb="*" /> <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions,PublicKeyToken=31BF3856AD364E35" validate="false" /> <add path="*_AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory,PublicKeyToken=31BF3856AD364E35" validate="false" /> <add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler,PublicKeyToken=31BF3856AD364E35" validate="false" /> <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,System.Web.DataVisualization,PublicKeyToken=31bf3856ad364e35" validate="false" /> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,PublicKeyToken=31BF3856AD364E35" /> </httpModules> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule,PublicKeyToken=31BF3856AD364E35" /> </modules> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="WebServiceHandlerFactory-Integrated" /> <remove name="ScriptHandlerFactory" /> <remove name="ScriptHandlerFactoryAppServices" /> <remove name="ScriptResource" /> <remove name="ChartImageHandler" /> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory,PublicKeyToken=31BF3856AD364E35" /> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory,PublicKeyToken=31BF3856AD364E35" /> <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler,PublicKeyToken=31BF3856AD364E35" /> <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,PublicKeyToken=31bf3856ad364e35" /> </handlers> <defaultDocument> <files> <add value="Login.aspx" /> </files> </defaultDocument> </system.webServer> <runtime> <assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
现web.config内容如下:
<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <connectionStrings> <add name="constr" connectionString="Provider=sqlOLEDB;Data Source=.;Initial Catalog=CzceTestSuite;User ID=sa;Password=sa13456;" /> <add name="conorclstr" connectionString="Provider=OraOLEDB.Oracle.1;User ID=xxxx;Password=1234qwer;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))" /> <add name="conorclserverstr" connectionString="Provider=OraOLEDB.Oracle.1;User ID=xxxx;Password=XXXX13579;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.123)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))" /> </connectionStrings> <system.webServer> <defaultDocument> <files> <add value="Login.aspx" /> </files> </defaultDocument> </system.webServer> </configuration>