从外部.config文件例外加载配置

时间:2012-12-19 16:20:13

标签: asp.net configurationmanager

我有以下继承自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>

这里是堆栈跟踪:

Framework.Web.Configuration.ExceptionsConfigurationSection.get_ExceptionsConfiguration()zh_cn Framework.Web.Filters.ExceptionFilter.OnException(ExceptionContext filterContext)zh C:\ inetpub \ wwwroot \ Projects \ Generic Website \ Framework.Web \ Filters \ ExceptionFilter。 cs:línea19zh 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 )zh_cn System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult `1.End()zh System.Web.Mvc.MvcHandler。&lt;&gt; c_ DisplayClasse.b _d()zh_cn System.Web.Mvc.SecurityUtil.b__0(Action f)en System。 Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)zh_cn System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)zh_cn System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)zh_cn System.Web。 HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()zh_cn System.Web.HttpApplication.Execu teStep(IExecutionStep步骤,布尔&amp; completedSynchronously)

我收到类ExceptionsConfiguration的类型inizialization错误...错误显示“元素HTMLMessage无法识别”

你能帮我一把吗?

由于

此致

0 个答案:

没有答案