{"id":144,"date":"2005-11-23T14:52:40","date_gmt":"2005-11-23T06:52:40","guid":{"rendered":"http:\/\/www.2lin.net\/?p=55"},"modified":"2005-11-23T14:52:40","modified_gmt":"2005-11-23T06:52:40","slug":"55","status":"publish","type":"post","link":"https:\/\/www.2lin.top\/?p=144","title":{"rendered":".net \u914d\u7f6e\u6587\u4ef6"},"content":{"rendered":"<p>\u5f00\u53d1asp.net\u5e94\u7528\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4e00\u822c\u90fd\u628a\u7cfb\u7edf\u7684\u73af\u5883\u914d\u7f6e\u4fe1\u606f\u653e\u5728web.config\u4e2d\uff0c\u5982\u679c\u53c2\u6570\u5f88\u5c11\uff0c\u4e00\u822c\u5c31\u76f4\u63a5\u653e\u5728&lt;appSettings&gt;\u914d\u7f6e\u8282\u4e2d\u5373\u53ef\u3002\u4f46\u5bf9\u4e8e\u4e00\u4e9b\u8f83\u5927\u578b\u7684\u5e94\u7528\uff0c\u6709\u5f88\u591a\u53c2\u6570\u9700\u8981\u8bbe\u7f6e\uff0c\u4ec5\u4f9d\u8d56\u4e8e&lt;appSettings&gt;\u7684\u5e73\u9762\u7ed3\u6784\u5c31\u4e0d\u591f\u4e86\uff0c\u9700\u8981\u4e00\u79cd\u80fd\u63d0\u4f9b\u591a\u5c42\u914d\u7f6e\u4fe1\u606f\u7684\u7ed3\u6784\u3002<\/p>\n<p>Dottext\u4e2d\u7684\u914d\u7f6e\u5c31\u662f\u8fd9\u6837\u4e00\u79cd\u591a\u5c42\u7684\u7ed3\u6784\uff0c\u5b83\u975e\u5e38\u5de7\u5999\u7684\u4f7f\u7528\u4e86.Net\u4e2d\u7684Xml\u5e8f\u5217\u5316\uff0c\u4f7f\u5f97\u914d\u7f6e\u7ed3\u6784\u975e\u5e38\u7b80\u5355\u5374\u53c8\u5f88\u5f3a\u5927\u3002 <\/p>\n<p>&nbsp;<\/p>\n<p>\u5f00\u53d1asp.net\u5e94\u7528\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4e00\u822c\u90fd\u628a\u7cfb\u7edf\u7684\u73af\u5883\u914d\u7f6e\u4fe1\u606f\u653e\u5728web.config\u4e2d\uff0c\u5982\u679c\u53c2\u6570\u5f88\u5c11\uff0c\u4e00\u822c\u5c31\u76f4\u63a5\u653e\u5728&lt;appSettings&gt;\u914d\u7f6e\u8282\u4e2d\u5373\u53ef\u3002\u4f46\u5bf9\u4e8e\u4e00\u4e9b\u8f83\u5927\u578b\u7684\u5e94\u7528\uff0c\u6709\u5f88\u591a\u53c2\u6570\u9700\u8981\u8bbe\u7f6e\uff0c\u4ec5\u4f9d\u8d56\u4e8e&lt;appSettings&gt;\u7684\u5e73\u9762\u7ed3\u6784\u5c31\u4e0d\u591f\u4e86\uff0c\u9700\u8981\u4e00\u79cd\u80fd\u63d0\u4f9b\u591a\u5c42\u914d\u7f6e\u4fe1\u606f\u7684\u7ed3\u6784\u3002&nbsp;&nbsp;<\/p>\n<p>Dottext\u4e2d\u7684\u914d\u7f6e\u5c31\u662f\u8fd9\u6837\u4e00\u79cd\u591a\u5c42\u7684\u7ed3\u6784\uff0c\u5b83\u975e\u5e38\u5de7\u5999\u7684\u4f7f\u7528\u4e86.Net\u4e2d\u7684Xml\u5e8f\u5217\u5316\uff0c\u4f7f\u5f97\u914d\u7f6e\u7ed3\u6784\u975e\u5e38\u7b80\u5355\u5374\u53c8\u5f88\u5f3a\u5927\u3002&nbsp;&nbsp;<\/p>\n<p>\u8981\u5411web.config\u4e2d\u52a0\u5165\u81ea\u5df1\u7684\u914d\u7f6e\u8282\uff0c\u5fc5\u987b\u5f00\u53d1\u76f8\u5e94\u7684\u914d\u7f6e\u8282\u5904\u7406\u7a0b\u5e8f\uff0cDottext\u4f7f\u7528\u4e86\u4e00\u4e2a\u516c\u5171\u7684\u914d\u7f6e\u8282\u5904\u7406\u7a0b\u5e8f\uff1a <\/p>\n<p>public class XmlSerializerSectionHandler : IConfigurationSectionHandler <\/p>\n<p>{<\/p>\n<p>public object Create(object parent, object configContext, System.Xml.XmlNode section) <\/p>\n<p>{<\/p>\n<p>XPathNavigator nav = section.CreateNavigator();<\/p>\n<p>string typename = (string) nav.Evaluate(&quot;string(@type)&quot;);<\/p>\n<p>Type t = Type.GetType(typename);<\/p>\n<p>XmlSerializer ser = new XmlSerializer(t);<\/p>\n<p>return ser.Deserialize(new XmlNodeReader(section));<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;\u5728web.config\u4e2d\u7684BlogConfigurationSettings\u914d\u7f6e\u8282\u5b9a\u4e49\u5982\u4e0b\uff1a <\/p>\n<p>&lt;BlogConfigurationSettings type = &quot;Dottext.Framework.Configuration.BlogConfigurationSettings, Dottext.Framework&quot;&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\uff0c\u4e00\u822c\u662f\u8fd9\u6837\u6765\u4f7f\u7528\u914d\u7f6e\u8bbe\u7f6e\uff1a<\/p>\n<p>Config.Settings.BlogProviders.DTOProvider<\/p>\n<p>&nbsp;<\/p>\n<p>\u800cSettings\u5728Config\u4e2d\u662f\u8fd9\u6837\u5b9a\u4e49\u7684\uff1a <\/p>\n<p>public static BlogConfigurationSettings Settings<\/p>\n<p>{<\/p>\n<p>get<\/p>\n<p>{<\/p>\n<p>return ((BlogConfigurationSettings)ConfigurationSettings.GetConfig(&quot;BlogConfigurationSettings&quot;));<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u5f53\u7528GetConfig\u83b7\u53d6ConfigurationSettings\u914d\u7f6e\u4fe1\u606f\u7684\u65f6\u5019\uff0c\u5b83\u4f1a\u8c03\u7528\u8be5\u914d\u7f6e\u8282\u7684\u5904\u7406\u7a0b\u5e8fXmlSerializerSectionHandler\u7684Create\u65b9\u6cd5\uff0c\u4ee5\u8fd4\u56de\u6b63\u786e\u7684\u914d\u7f6e\u8bbe\u7f6e\u3002\u5728\u5176Create\u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7\u8bbf\u95ee\u914d\u7f6e\u8282\u7684type\u5c5e\u6027\u6765\u5f97\u5230\u5177\u4f53\u7c7b\u578b\uff0c\u7136\u540e\u901a\u8fc7XmlSerializer\u5c06web.config\u4e2d\u7684\u4ee5xml\u683c\u5f0f\u914d\u7f6e\u7684\u8bbe\u7f6e\u4fe1\u606f\u53cd\u5e8f\u5217\u5316\u4e3a\u5177\u4f53\u7684BlogConfigurationSettings\u5bf9\u8c61\u3002 <\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u4e2d\u95f4\u7684\u5173\u952e\u5c31\u662f\u8981\u5b9a\u4e49\u597d\u63d0\u4f9b\u914d\u7f6e\u4fe1\u606f\u7684\u7c7b&mdash;&mdash;BlogConfigurationSettings\uff0c\u8fd9\u6837\u6211\u4eec\u624d\u80fd\u4f7f\u7528\u7c7b\u4f3cConfig.Settings.UseXHTML\u7684\u65b9\u5f0f\u83b7\u53d6\u5728web.config\u4e2d\u5b9a\u4e49\u7684\u53c2\u6570\uff0c\u800c\u4e0d\u662f\u4f7f\u7528Convert.ToBoolean(AppSettings[&quot;Blog.UseXHTML&quot;])\u3002 <\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u7c7b\u53ea\u8981\u52a0\u4e0aSerializable\u7279\u6027\u8fdb\u884c\u58f0\u660e\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u8fd9\u6837\u7684\u914d\u7f6e\u7c7b\u4e86\uff1a<\/p>\n<p>[Serializable]<\/p>\n<p>public class BlogConfigurationSettings <\/p>\n<p>&nbsp;<\/p>\n<p>\u4f46\u4ecd\u7136\u8981\u6ce8\u610f\u51e0\u70b9\uff1ainterface\u548cabstract class\u4e0d\u80fd\u4f5c\u4e3a\u914d\u7f6e\u7c7b\uff1b\u7c7b\u5fc5\u987b\u8981\u6709\u4e0d\u5e26\u53c2\u6570\u7684\u516c\u5171\u6784\u9020\u51fd\u6570\uff1b\u8981\u4f5c\u4e3a\u914d\u7f6e\u53c2\u6570\u7684\u5b57\u6bb5\u6216\u8005\u5c5e\u6027\u5fc5\u987b\u662fpublic\u7684\uff0c\u800c\u5c5e\u6027\u5fc5\u987b\u6709set\u3002 <\/p>\n<p>&nbsp;<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cXml\u5e8f\u5217\u5316\u4f1a\u628a\u7c7b\u4e2d\u7684\u5b57\u6bb5\u6216\u8005\u5c5e\u6027\u5e8f\u5217\u5316\u6210xml Element\uff0c\u6bd4\u5982\u4e0a\u9762\u7684UseXHTML\uff0c\u4f46\u6709\u4e9b\u65f6\u5019\uff0c\u53ef\u80fd\u8981\u4f7f\u7528xml Attribute\uff0c\u6bd4\u5982\uff1a <\/p>\n<p>&lt;Tracking enableAggBugs = &quot;true&quot; &hellip; <\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\uff0c\u9700\u8981\u4f7f\u7528XmlAttributeAttribute\u6765\u58f0\u660e\uff1a<\/p>\n<p>[XmlAttribute(&quot;enableAggBugs&quot;)]<\/p>\n<p>public bool EnableAggBugs<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5b9a\u4e49\u7684\u914d\u7f6e\u7c7b\u5e94\u8be5\u5df2\u7ecf\u8db3\u591f\uff0c\u4f46\u5076\u5c14\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u589e\u52a0\u914d\u7f6e\u5143\u7d20\u6216\u8005\u914d\u7f6e\u5c5e\u6027\uff0c\u4f46\u53c8\u4e0d\u80fd\u6216\u8005\u4e0d\u60f3\u4fee\u6539\u5df2\u6709\u7684\u914d\u7f6e\u7c7b\uff0c\u4e3a\u4e86\u907f\u514d\u53cd\u5e8f\u5217\u5316\u7684\u65f6\u5019\u51fa\u9519\uff0c\u4e5f\u4e3a\u4e86\u589e\u5f3a\u7075\u6d3b\u6027\uff0c\u5e94\u8be5\u7ed9\u914d\u7f6e\u7c7b\u589e\u52a0\u8fd9\u6837\u4e24\u4e2a\u5c5e\u6027\uff1a<\/p>\n<p>[XmlAnyAttribute]<\/p>\n<p>public XmlAttribute[] XmlAttributes<\/p>\n<p>&nbsp;<\/p>\n<p>[XmlAnyElement]<\/p>\n<p>public XmlElement[] XmlElements<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u662f\u544a\u8bc9XmlSerializer\uff0c\u5982\u679c\u6709\u4e0d\u53ef\u8bc6\u522b\u7684\u5143\u7d20\u6216\u8005\u5c5e\u6027\uff0c\u5219\u5c06\u5176\u653e\u5230\u8fd9\u6837\u4e24\u4e2a\u6570\u7ec4\u4e2d\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u4ece\u6570\u7ec4\u4e2d\u68c0\u7d22\u76f8\u5e94\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Dottext\u4e2d\u8fd8\u5b9a\u4e49\u4e86\u8fd9\u6837\u7684\u7ed3\u6784\uff1a <\/p>\n<p>&lt;EntryHandlers&gt;<\/p>\n<p>&lt;EntryHandler type=&quot;&#8230;&quot; postType = &quot;Comment&quot; processAction =&quot;Insert&quot; processState=&quot;PreCommit&quot; isAsync=&quot;false&quot; \/&gt;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/EntryHandlers&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>[XmlArray(&quot;EntryHandlers&quot;)]<\/p>\n<p>public EntryHandler[] EntryHandlers<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9a\u4e49\u6570\u7ec4\u53c2\u6570\u3002\u5982\u679c\u6570\u7ec4\u7684\u5143\u7d20\u4e0d\u662f\u540c\u6837\u7684\u7c7b\u578b\uff0c\u4f46\u90fd\u7ee7\u627f\u81ea\u4e00\u4e2a\u57fa\u7c7b\uff0c\u90a3\u8fd8\u53ef\u4ee5\u8fd9\u6837\u5b9a\u4e49\uff1a<\/p>\n<p>&lt;Validators&gt;<\/p>\n<p>&lt;RegularExpressionValidator Name=&quot;Email&quot; &#8230;<\/p>\n<p>&lt;DateValidator Name=&quot;Date&quot; &#8230;<\/p>\n<p>&#8230;<\/p>\n<p>&lt;\/Validators&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>[XmlArray(&quot;Validators&quot;)]<\/p>\n<p>[<\/p>\n<p>XmlArrayItem(&quot;Validator&quot;, typeof(Nss.Data.Validators.Validator))<\/p>\n<p>,<\/p>\n<p>XmlArrayItem(&quot;RegularExpressionValidator&quot;, typeof(Nss.Data.Validators.RegularExpressionValidator))<\/p>\n<p>]<\/p>\n<p>public Nss.Data.Validators.Validator[] Validators;<\/p>\n<p>&nbsp;<\/p>\n<p>XmlArray\u5b9a\u4e49\u4e86\u6570\u7ec4\uff0c\u800cXmlArrayItem\u5b9a\u4e49\u4e86\u6570\u7ec4\u4e2d\u53ef\u4ee5\u4f7f\u7528\u7684\u5143\u7d20\u7c7b\u578b\uff0c\u4f7f\u5f97\u7cfb\u7edf\u7684\u914d\u7f6e\u66f4\u52a0\u7075\u6d3b\uff0c\u7ed3\u6784\u4e5f\u66f4\u6e05\u6670\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u53d1asp.net\u5e94\u7528\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4e00\u822c\u90fd\u628a\u7cfb\u7edf\u7684\u73af\u5883\u914d\u7f6e\u4fe1\u606f\u653e\u5728web.config\u4e2d\uff0c\u5982\u679c\u53c2\u6570\u5f88\u5c11\uff0c\u4e00\u822c\u5c31\u76f4\u63a5\u653e\u5728&lt;appSettings&gt;\u914d\u7f6e\u8282\u4e2d\u5373\u53ef\u3002\u4f46\u5bf9\u4e8e\u4e00&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts\/144"}],"collection":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=144"}],"version-history":[{"count":0,"href":"https:\/\/www.2lin.top\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.2lin.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}