加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 用于Web.config的T4MVC

发布时间:2020-12-16 07:28:13 所属栏目:asp.Net 来源:网络整理
导读:关于 T4MVC的好处是它可以让你摆脱 literal/magic strings. T4MVC is a T4 template for ASP.NET MVC apps that creates strongly typed helpers that eliminate the use of literal strings when referring the controllers,actions and views. 我只是想知
关于 T4MVC的好处是它可以让你摆脱 literal/magic strings.

T4MVC is a T4 template for ASP.NET MVC apps that creates strongly
typed helpers that eliminate the use of literal strings when referring
the controllers,actions and views.

我只是想知道在Web.config文件中的应用程序设置是否可能有类似的东西:

<appSettings>
    <add key="SecurityGuardEmailFrom" value="info@email.net" />
    <add key="PasswordExpiresInDays" value="1" />
    <add key="NumberOfPasswordsToKeep" value="5" />
</appSettings>

所以,而不是这个:

private static readonly int PasswordExpiresInDays =
int.Parse(ConfigurationManager.AppSettings["PasswordExpiresInDays"]);

我们有这样的事情:

MVC.Webconfig.PasswordExpiresInDays

要么

MVC.AppSettings.PasswordExpiresInDays

这将有助于在编译时检查应用程序设置是否仍在那里避免运行时错误.

这甚至可行吗?如果是的话,你知道是否已经在某处实现了类似的东西吗?

解决方法

创建自定义配置部分,而不是将您的设置放在< appSettings>中.

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

You can extend ASP.NET configuration settings with XML configuration elements of your own. To do this,you create a custom configuration section handler. The handler must be a .NET Framework class that inherits from the System.Configuration.ConfigurationSection class. The section handler interprets and processes the settings that are defined in XML configuration elements in a specific section of a Web.config file. You can read and write these settings through the handler’s properties.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读