我在web.config文件中添加了以下设置,以启动对外部系统的API调用.所以我存储API URL +用户名+密码如下: -
<appSettings>
<add key="ApiURL" value="https://...../servlets/AssetServlet" />
<add key="ApiUserName" value="tmsservice" />
<add key="ApiPassword" value="test2test2" />
Run Code Online (Sandbox Code Playgroud)
然后在我的action方法中,我将在构建Web客户端时引用这些值,如下所示: -
public ActionResult Create(RackJoin rj, FormCollection formValues)
{
XmlDocument doc = new XmlDocument();
using (var client = new WebClient())
{
var query = HttpUtility.ParseQueryString(string.Empty);
foreach (string key in formValues)
{
query[key] = this.Request.Form[key];
}
query["username"] = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiUserName"];
query["password"] = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiPassword"];
string apiurl = System.Web.Configuration.WebConfigurationManager.AppSettings["ApiURL"];
Run Code Online (Sandbox Code Playgroud)
但在这一点上,我将公开用户名和密码,这些可以被用户捕获,所以我的问题是如何保护API用户名和密码?