我有以下类继承自 ConfigurationSection
public class ExceptionsConfiguration:ConfigurationSection
{
private static ExceptionsConfiguration _exceptionsconfig = ConfigurationManager.GetSection("ExceptionsConfig") as ExceptionsConfiguration;
/// <summary>
/// Static accessible configuration
/// </summary>
public static ExceptionsConfiguration ExceptionsConfig
{
get
{
return _exceptionsconfig;
}
}
//HTML message with the exception to be sent by email
public string HTMLMessage { get; set; }
//Subject of the email
public string Subject { get; set; }
//UserName of the email account to use
public string FromLabel { get; set; }
//Password of the email
public string Password { get; set; }
//Email account used to send the email
public string Email { get; set; }
//To account to send email with exception
public string To{get;set;}
//Smtp server used to send the email
public string SmtpServer{get;set;}
//Port used to send the email
public int Port{get;set;}
}
另一方面,我在 web.config 上声明了我的部分
<configSections>
<section name="ExceptionsConfig" type="Framework.Web.Configuration.ExceptionsConfiguration" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<ExceptionsConfig configSource="Config\ExceptionsConfig.config"/>
最后是我的配置文件:
<ExceptionsConfig>
<HTMLMessage>
<![CDATA[
<p> DataService:{0}</p>
<p> AvailableCategories:{1} </p>
<p> Queries:{2} </p>
<p> Exception:{3} </p>
<p> Is child action:{4} </p>
<p> Action executed:{5} </p>
<p> Controller executed:{6} </p>
<p> Current URL: {7} </p>
<p> Headers start </p>
<p> {8} </p>
<p> Headers end </p>
<p> IP adress: {9}
]]>
</HTMLMessage>
<Subject>Exception on www.</Subject>
<FromLabel>Exception watcher from</FromLabel>
<Password>zzzzz</Password>
<Email>xxxxxx@xxxxx.com</Email>
<To>yyyyyy@yyyyyyy.com</To>
<SmtpServer>smtp.nnnnnnn.com</SmtpServer>
<Port>000</Port>
</ExceptionsConfig>
这里是堆栈跟踪:
zh Framework.Web.Configuration.ExceptionsConfigurationSection.get_ExceptionsConfiguration() zh Framework.Web.Filters.ExceptionFilter.OnException(ExceptionContext filterContext) zh C:\inetpub\wwwroot\Projects\Generic Website\Framework.Web\Filters\ExceptionFilter.cs:línea 19 System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList 1 filters, Exception exception) en System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) en System.Web.Mvc.Controller.ExecuteCore() en System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) en System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) en System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() en System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() en System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8
1.b_ 7(IAsyncResult ) en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() en System.Web.Mvc.MvcHandler。 <> c_DisplayClasse.b_d() en System.Web.Mvc.SecurityUtil.b__0(Action f) en System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) en System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) en System.Web。 Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) en System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() en System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我收到类 ExceptionsConfiguration 的类型初始化错误...并且错误显示"Element HTMLMessage not Recognized"。
你能帮我一把吗?
谢谢
问候
何塞