本文介绍了如何用ASP.NET MVC中的ELMAH解决SQL服务器问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 <结构> < configSections> < sectionGroup name =elmah> < section name =securityrequirePermission =falsetype =Elmah.SecuritySectionHandler,Elmah/> < section name =errorLogrequirePermission =falsetype =Elmah.ErrorLogSectionHandler,Elmah/> < section name =errorMailrequirePermission =falsetype =Elmah.ErrorMailSectionHandler,Elmah/> < section name =errorFilterrequirePermission =falsetype =Elmah.ErrorFilterSectionHandler,Elmah/> < / sectionGroup> < section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFrameworkrequirePermission =false/> < / configSections> < connectionStrings> < add name =SCEconnectionString =metadata = res://*/SCE.csdl | res://*/SCE.ssdl | res://*/SCE.msl; provider = System .Data.SqlClient; provider connection string =data source = 11.234.135.5; initial catalog = SCE2; persist security info = True; user id = ddd; password = sss; MultipleActiveResultSets = True; App = EntityFrameworkproviderName =System .Data.EntityClient/> < / connectionStrings> < appSettings> < add key =webpages:Versionvalue =2.0.0.0/> < add key =webpages:Enabledvalue =false/> < add key =PreserveLoginUrlvalue =true/> < add key =ClientValidationEnabledvalue =true/> < add key =UnobtrusiveJavaScriptEnabledvalue =true/> < add key =ClientValidationEnabledvalue =true/> < add key =UnobtrusiveJavaScriptEnabledvalue =true/> < / appSettings> < system.web> < customErrors mode =OffdefaultRedirect =/ Error / Error> < error statusCode =403redirect =/ Error / NoPermissions/> < / customErrors> < globalization uiCulture =en-GBculture =en-GB/> < compilation targetFramework =4.5debug =true/> < httpRuntime targetFramework =4.5maxRequestLength =10240requestLengthDiskThreshold =10024000enableVersionHeader =false/> < authentication mode =Forms> < forms loginUrl =〜/ Account / Indextimeout =2880/> < / authentication> < pages> < namespaces> < add namespace =System.Web.Helpers/> < add namespace =System.Web.Mvc/> < add namespace =System.Web.Mvc.Ajax/> < add namespace =System.Web.Mvc.Html/> < add namespace =System.Web.Optimization/> < add namespace =System.Web.Routing/> < add namespace =System.Web.WebPages/> < / namespaces> < / pages> < sessionState timeout =2800mode =StateServer> < / sessionState> < httpHandlers> < add verb =POST,GET,HEADpath =elmah.axdtype =Elmah.ErrorLogPageFactory,Elmah/> < / httpHandlers> < httpModules> < add name =ErrorLogtype =Elmah.ErrorLogModule,Elmah/> < add name =ErrorMailtype =Elmah.ErrorMailModule,Elmah/> < add name =ErrorFiltertype =Elmah.ErrorFilterModule,Elmah/> < / httpModules> < /system.web> < system.webServer> < handlers> < remove name =ExtensionlessUrlHandler-ISAPI-4.0_32bit/> < remove name =ExtensionlessUrlHandler-ISAPI-4.0_64bit/> < remove name =ExtensionlessUrlHandler-Integrated-4.0/> < add name =ExtensionlessUrlHandler-ISAPI-4.0_32bitpath =*。 verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptProcessor =%windir%\ Mesrosoft.NET \ Framework\v4.0.30319\aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness32responseBufferLimit =0/> < add name =ExtensionlessUrlHandler-ISAPI-4.0_64bitpath =*。 verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSmodules =IsapiModulescriptProcessor =%windir%\ Mesrosoft.NET \ Framework64 \v4.0.30319 \ aspnet_isapi.dllprecondition =classicMode,runtimeVersionv4.0,bitness64responseBufferLimit =0/> < add name =ExtensionlessUrlHandler-Integrated-4.0path =*。 verb =GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONStype =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/> < add name =ELMAHverb =POST,GET,HEADpath =elmah.axdtype =Elmah.ErrorLogPageFactory,ElmahpreCondition =integratedMode/> < / handlers> < modules runAllManagedModulesForAllRequests =true> < add name =Elmah.ErrorLogtype =Elmah.ErrorLogModule,ElmahpreCondition =managedHandler/> < add name =Elmah.ErrorMailtype =Elmah.ErrorMailModulepreCondition =managedHandler/> < add name =ErrorFiltertype =Elmah.ErrorFilterModule,ElmahpreCondition =managedHandler/> < / modules> < validation validateIntegratedModeConfiguration =false/> < /system.webServer> < entityFramework> < defaultConnectionFactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework> < parameters> < parameter value =v11.0/> < / parameters> < / defaultConnectionFactory> < / entityFramework> < elmah> < security allowRemoteAccess =0/> < errorLog type =Elmah.SqlErrorLog,ElmahconnectionStringName =SCE/> < errorMail from [email protected] [email protected] =ELMAH错误登录SCasync =true>< / errorMail> < / elmah> < / configuration> 我的尝试: 以上是我的web.configuration文件。 问题1:在坏URL上,电子邮件被发送到emailid但未保存在Sql数据库中 b $ b 问题2:我无法看到elmah.axd文件。注意:我有身份验证模式表单。 请帮忙。解决方案 这是一个明显的问题: < errorLog type = Elmah.SqlErrorLog,Elmah connectionStringName = SolutionCentreEntities / > 查看< connectionStrings> 部分 - 您定义的唯一连接字符串是名为 SCE 。 ELMAH不使用实体框架。您需要定义一个名为 SolutionCentreEntities 的标准SQL连接字符串,指向您创建的ELMAH数据库。 如果您还没有这样做,则需要下载 [ ^ ]并运行MS SQL Server DDL脚本。 终极ELMAH教程:登录到SQL Server [ ^ ] 配置ELMAH以使用SQL Server~andyfrench.info [ ^ ] <configuration> <configSections> <sectionGroup name="elmah"> <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" /> <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" /> <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /> <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" /> </sectionGroup> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" /> </configSections> <connectionStrings> <add name="SCE" connectionString="metadata=res://*/SCE.csdl|res://*/SCE.ssdl|res://*/SCE.msl;provider=System.Data.SqlClient;provider connection string="data source=11.234.135.5;initial catalog=SCE2;persist security info=True;user id=ddd;password=sss;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> <appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <customErrors mode="Off" defaultRedirect="/Error/Error"> <error statusCode="403" redirect="/Error/NoPermissions" /> </customErrors> <globalization uiCulture="en-GB" culture="en-GB" /> <compilation targetFramework="4.5" debug="true" /> <httpRuntime targetFramework="4.5" maxRequestLength="10240" requestLengthDiskThreshold="10024000" enableVersionHeader="false" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Index" timeout="2880" /> </authentication> <pages> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Optimization" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> </namespaces> </pages> <sessionState timeout="2800" mode="StateServer"> </sessionState> <httpHandlers> <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> </httpHandlers> <httpModules> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> </httpModules> </system.web> <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" /> </handlers> <modules runAllManagedModulesForAllRequests="true"> <add name="Elmah.ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> <add name="Elmah.ErrorMail" type="Elmah.ErrorMailModule" preCondition="managedHandler" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <elmah> <security allowRemoteAccess="0" /> <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="SCE"/> <errorMail from="[email protected]" to="[email protected]" subject="ELMAH Error Logged on SC" async="true"></errorMail> </elmah></configuration>What I have tried:The above is my web.configuration file.Problem 1 : On bad url the email is sent to emailid but not saved in Sql databaseproblem 2 : i am not able to see elmah.axd file . Note : i have Authentication mode Forms.Please help. 解决方案 Here's the obvious problem:<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="SolutionCentreEntities"/>Look at your <connectionStrings> section - the only connection string you've defined is an Entity Framework connection called SCE.ELMAH doesn't use Entity Framework. You'll need to define a standard SQL connection string called SolutionCentreEntities, pointing to the ELMAH database you created.If you haven't done so already, you'll need to download[^] and run the "MS SQL Server DDL Script".The Ultimate ELMAH Tutorial: Logging to SQL Server[^]Configuring ELMAH to use SQL Server ~ andyfrench.info[^] 这篇关于如何用ASP.NET MVC中的ELMAH解决SQL服务器问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-14 06:47