开发者

How to create a settings file external to web.config

开发者 https://www.devze.com 2023-02-06 14:06 出处:网络
I want to create a settings file external to web.config in my ASP.NET MVC 2.0 project and I\'m not sure of the best way to go about this. What ways do you recommend for creating a settings file that w

I want to create a settings file external to web.config in my ASP.NET MVC 2.0 project and I'm not sure of the best way to go about this. What ways do you recommend for creating a settings file that will contain 开发者_JS百科sensitive information to be excluded from source control.


You could use the special App_Data folder to store your settings file. Direct access to this folder is denied by ASP.NET. As far as the format of this file is concerned XML seems a good format. But whatever format you choose make sure you provide a strongly typed API that will allow you to access those settings so that you don't find yourself parsing XML in the middle of a controller action. In Application_Start you could parse it and store the values in some structure which will be accessible through the entire application. And because it is in Application_Start that you are doing this you could use it along with your favourite DI framework to pass those values to all classes that might need them such as controllers and repositories.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号