public ActionResult SaveWebConfig(HTAccessModel model) { if (!model.AcceptTerms) { ViewBag.Message = "Please indicate you understand the file will be overwritten."; ViewBag.AlertType = "danger"; return(View("Import", model)); } try { using (var stream = new StreamWriter(WebConfigPath, false)) { stream.Write(model.WebConfigFile); } ViewBag.AlertType = "success"; ViewBag.Message = "<h3>Save Successful!</h3><p>To ensure that this file persists across deployments, please <a href=\"/vfs/site/wwwroot/web.config\">download</a> the <code>web.config</code> file to replace your local copy.</p>"; } catch (IOException ioe) { ViewBag.Message = string.Format("Error saving web.config file. Output: {0}", ioe.Message); ViewBag.AlertType = "danger"; } ModelState.Clear(); return(View("Import", model)); }
public ActionResult Import(HTAccessModel model) { if (model.UploadedFile != null) { string htaccess = string.Empty; using (var reader = new StreamReader(model.UploadedFile.InputStream)) { htaccess = reader.ReadToEnd(); } model.HTAccessFile = htaccess; } else { ModelState.Clear(); } model.WebConfigFile = ConvertHTAccessToWebConfig(model.HTAccessFile); return(View(model)); }