Best Way to store configuration setting inside my asp.net mvc application

后端 未结 1 794
名媛妹妹
名媛妹妹 2020-12-28 07:58

I am working on a asp.net mvc web application that perform some API calls to other web applications. but currently I am storing the API username, API password and API URL in

相关标签:
1条回答
  • 2020-12-28 08:49

    You should use the Web.Config file (Configuration API) to store these settings. This way you will be able to update settings without having to recompile your entire application every time. That's the most standard way to store settings in a Web (MVC or WebForms) application, and gives you the possibility to encrypt sensitive settings transparently to your application.

    You can access stored settings using the WebConfigurationManager class. Here you can find some examples of how to use it.

    Code sample:

    Web.config appSettings:

    <appSettings>
        <add key="ApiUserName" value="MySampleUsername" />
    </appSettings>
    

    C# Code:

    string userName = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiUserName"];
    
    0 讨论(0)
提交回复
热议问题