public async Task <ActionResult> DocumentDBCredentials(DocumentDBCredentialsViewModel model) { Trace.WriteLine("Entering DocumentDBCredentials POST method"); if (ModelState.IsValid) { //Check if Database is accessible Task <bool> flag = DocumentDBDataController.IsDatabaseAccessible(model.EndPointUrl, model.AuthorizationKey); if (flag.Result) { //Helps to open the Root level web.config file. Configuration webConfigApp = WebConfigurationManager.OpenWebConfiguration("~"); //Modifying the AppKey from AppValue to AppValue1 webConfigApp.AppSettings.Settings["EndpointUrl"].Value = model.EndPointUrl; webConfigApp.AppSettings.Settings["AuthorizationKey"].Value = model.AuthorizationKey; //Save the Modified settings of AppSettings. webConfigApp.Save(); //Update the configuration.xml file in Agent Application with Endpoint Url and Authorization Key. AgentController agent = new AgentController(); Trace.TraceInformation(DateTime.Now.ToLongTimeString() + "Calling CreateSetting method"); agent.UpdateAgentConfiguration(model.EndPointUrl, model.AuthorizationKey); return(RedirectToAction("AgentDownload", "Account")); } else { ViewBag.ErrorMessage = "DocumentDB database is not accessible"; return(View("Error")); } } // If we got this far, something failed, redisplay form return(View(model)); }