3

I am starting Asp Net MVC4 project and since I am comming from php development I am curious about what would it be the best way to set-up a configuration file to store parameters like system name, version and others that I might need.

Is there any guideline to do that for instance using a config file or a database query..?

4

1 回答 1

5

我广泛使用 web.config 来处理这类事情。

例子

<appSettings>
    ....
    <add key="SearchUserResultMaxCount" value="100" />
</appSettings>

代码

public static class SearchHelper
{
    /// <summary>
    /// Gets the max records for resultset from db, configurable in web.config
    /// </summary>
    /// <returns></returns>
    public static int SearchEntityResultMaxCount()
    {
        int count;
        Int32.TryParse(ConfigurationManager.AppSettings["SearchEntityResultMaxCount"], out count);
        return count;
    }
}
于 2013-05-23T20:20:16.333 回答