我有一个字符串字典,我希望用户能够添加/删除信息然后存储它们,以便他们可以在下次程序重新启动时访问它
我不知道如何将字典存储为设置.我看到在system.collections.special下有一个叫做stringdictionary的东西,但我读过SD已经过时了,不应该使用它.
同样在将来我可能需要存储一个不仅仅是字符串的字典(int string)
如何在.net应用程序的设置文件中存储字典?
我想在我的ASP.NET Web应用程序的应用程序设置中存储一组键/值对,但我找不到直接的方法来做到这一点.例如,这两个 问题告诉我,StringDictionary等不会序列化为XML,并建议我必须推出自己的实现.但似乎这应该更容易做到; 毕竟,web.config是XML,<applicationSettings>本质上是键/值对的集合,所以感觉我错过了一些明显的东西.鉴于我的具体情况如下,我是否真的必须推出自己的序列化,还是有更简单的解决方法?
有问题的Web应用程序是一个基本联系表单,它根据参数的值向不同的收件人发送电子邮件; 例如http://www.examplesite.com/Contact.aspx?recipient=support会发送电子邮件至SupportGroup@exampledomain.com.
目标是通过编辑web.config文件来添加或删除收件人(或更改其地址),这样我就不必重新编译,并且可以在测试和生产环境中轻松维护不同的配置.例如:
// I can use something like this for the sender address
SmtpMsg.From = New MailAddress(My.Settings.EmailSender)
// And then just edit this part of web.config to use
// different addresses in different environments.
<setting name="EmailSender" serializeAs="String">
<value>webcontact@exampledomain.com</value>
</setting>
// I want something like this for the recipients
SmtpMsg.To.Add(My.Settings.Recipients("support"))
// and presumably some sort of equivalent xml in web.config
// maybe something like this???
<recipients>
<item name="support" serializeAs="String">
<value>SupportGroup@exampledomain.com</value>
</item>
<!-- …Run Code Online (Sandbox Code Playgroud)