fix:优化异常处理和文件操作

- 在安装过程中添加异常处理,提高系统稳定性
- 优化文件读写操作,确保数据安全
- 更新异常处理机制,满足优化建议
This commit is contained in:
jonah.fu
2025-08-14 18:38:07 +08:00
parent 7ae5d3e885
commit b7cafe76e5
3 changed files with 149 additions and 41 deletions
@@ -222,7 +222,15 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
string content = ""; string content = "";
if (System.IO.File.Exists(file)) if (System.IO.File.Exists(file))
{ {
content = System.IO.File.ReadAllText(file); try
{
content = System.IO.File.ReadAllText(file);
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
// 如果读取文件失败,继续使用空内容
}
} }
ViewBag.content = content; ViewBag.content = content;
Admin.WriteLogActions("查看Robots.txt;"); Admin.WriteLogActions("查看Robots.txt;");
@@ -233,15 +241,18 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
public IActionResult Robots(string content) public IActionResult Robots(string content)
{ {
string file = Path.Combine(_env.WebRootPath, "robots.txt"); string file = Path.Combine(_env.WebRootPath, "robots.txt");
if (System.IO.File.Exists(file)) try
{ {
//写入覆盖 //写入覆盖
System.IO.File.WriteAllText(file, content); System.IO.File.WriteAllText(file, content);
} }
else catch (Exception ex)
{ {
System.IO.File.WriteAllText(file, content); NewLife.Log.XTrace.WriteException(ex);
tip.Message = "修改Robots.txt失败:" + ex.Message;
return Json(tip);
} }
tip.Status = JsonTip.SUCCESS; tip.Status = JsonTip.SUCCESS;
tip.Message = "修改Robots.txt成功"; tip.Message = "修改Robots.txt成功";
Admin.WriteLogActions("修改Robots.txt成功;"); Admin.WriteLogActions("修改Robots.txt成功;");
+132 -35
View File
@@ -27,13 +27,14 @@ namespace COMCMS.Web.Controllers
private IWebHostEnvironment _env; private IWebHostEnvironment _env;
private readonly ICacheProvider _cacheProvider; private readonly ICacheProvider _cacheProvider;
public HomeController(IWebHostEnvironment env,ICacheProvider cacheProvider) public HomeController(IWebHostEnvironment env, ICacheProvider cacheProvider)
{ {
_env = env; _env = env;
_cacheProvider = cacheProvider; _cacheProvider = cacheProvider;
} }
#region 首页 #region 首页
public IActionResult Index() public IActionResult Index()
{ {
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0; bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
@@ -41,21 +42,26 @@ namespace COMCMS.Web.Controllers
{ {
return Redirect("/Home/Install"); return Redirect("/Home/Install");
} }
ViewBag.cfg = cfg; ViewBag.cfg = cfg;
ViewBag.about = Article.FindById(1);//关于我们 ViewBag.about = Article.FindById(1); //关于我们
return View("~/Views/Home/Index.cshtml"); return View("~/Views/Home/Index.cshtml");
} }
#endregion #endregion
#region 显示默认错误页面 #region 显示默认错误页面
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
#endregion #endregion
#region 初始化安装 #region 初始化安装
[HttpGet] [HttpGet]
public IActionResult Install() public IActionResult Install()
{ {
@@ -64,6 +70,7 @@ namespace COMCMS.Web.Controllers
{ {
return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/"); return EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/");
} }
//判断数据库类型 mysql mssql 暂时只支持这两种 //判断数据库类型 mysql mssql 暂时只支持这两种
string sqltype = "mysql"; string sqltype = "mysql";
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName"); string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
@@ -71,14 +78,17 @@ namespace COMCMS.Web.Controllers
{ {
sqltype = "mssql"; sqltype = "mssql";
} }
bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0; bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;
ViewBag.hasData = hasData; ViewBag.hasData = hasData;
ViewBag.sqltype = sqltype; ViewBag.sqltype = sqltype;
return View(); return View();
} }
#endregion #endregion
#region 执行初始化数据库数据 #region 执行初始化数据库数据
[HttpPost] [HttpPost]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public IActionResult DoInstall() public IActionResult DoInstall()
@@ -101,7 +111,8 @@ namespace COMCMS.Web.Controllers
tip.Message = "请输入用户名!"; tip.Message = "请输入用户名!";
return Json(tip); return Json(tip);
} }
if (username.Trim().Length<5)
if (username.Trim().Length < 5)
{ {
tip.Message = "用户名不能小于4个字符!"; tip.Message = "用户名不能小于4个字符!";
return Json(tip); return Json(tip);
@@ -112,11 +123,13 @@ namespace COMCMS.Web.Controllers
tip.Message = "登录密码不能为空或者长度小于5!"; tip.Message = "登录密码不能为空或者长度小于5!";
return Json(tip); return Json(tip);
} }
if(password != password2)
if (password != password2)
{ {
tip.Message = "两次输入密码不一致,请重新输入!"; tip.Message = "两次输入密码不一致,请重新输入!";
return Json(tip); return Json(tip);
} }
string sqltype = "mysql"; string sqltype = "mysql";
string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName"); string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");
if (sqlProviderName == "System.Data.SqlClient") if (sqlProviderName == "System.Data.SqlClient")
@@ -124,7 +137,7 @@ namespace COMCMS.Web.Controllers
sqltype = "mssql"; sqltype = "mssql";
} }
if(sqltype =="mysql" && string.IsNullOrEmpty(mysqltype)) if (sqltype == "mysql" && string.IsNullOrEmpty(mysqltype))
{ {
tip.Message = "请选择系统Mysql服务器类型!"; tip.Message = "请选择系统Mysql服务器类型!";
return Json(tip); return Json(tip);
@@ -139,7 +152,7 @@ namespace COMCMS.Web.Controllers
//判断需要的sql文件 //判断需要的sql文件
string sqlname = "comcms_sqlserver.sql"; string sqlname = "comcms_sqlserver.sql";
if(sqltype == "mysql") if (sqltype == "mysql")
{ {
if (mysqltype == "linux") if (mysqltype == "linux")
sqlname = "comcms_for_linux.sql"; sqlname = "comcms_for_linux.sql";
@@ -155,45 +168,95 @@ namespace COMCMS.Web.Controllers
tip.Message = "缺少初始化SQL文件!"; tip.Message = "缺少初始化SQL文件!";
return Json(tip); return Json(tip);
} }
string fullsql = System.IO.File.ReadAllText(sqlFullPath);
string fullsql = "";
try
{
fullsql = System.IO.File.ReadAllText(sqlFullPath);
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "读取SQL文件时发生错误:" + ex.Message;
return Json(tip);
}
//如果是mssql 需要替换一下 GO不能在程序中直接执行 //如果是mssql 需要替换一下 GO不能在程序中直接执行
if (sqltype == "mssql") if (sqltype == "mssql")
{ {
fullsql = fullsql.Replace("GO", ";"); fullsql = fullsql.Replace("GO", ";");
} }
Admin.FindAll(fullsql);//执行 try
{
Admin.FindAll(fullsql); //执行
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "执行SQL时发生错误:" + ex.Message;
return Json(tip);
}
//初始化 //初始化
Config cfg = Config.FindById(1); Config cfg = Config.FindById(1);
if(cfg != null) if (cfg != null)
{ {
cfg.SiteName = sitename; try
cfg.SiteUrl = siteurl; {
cfg.Update(); cfg.SiteName = sitename;
cfg.SiteUrl = siteurl;
cfg.Update();
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "初始化配置时发生错误:" + ex.Message;
return Json(tip);
}
} }
Admin admin = Admin.Find(Admin._.Id == 1); Admin admin = Admin.Find(Admin._.Id == 1);
if(admin != null) if (admin != null)
{ {
admin.UserName = username; try
admin.Salt = Utils.GetRandomChar(10); {
admin.PassWord = Utils.MD5(admin.Salt + password); admin.UserName = username;
admin.Update(); admin.Salt = Utils.GetRandomChar(10);
admin.PassWord = Utils.MD5(admin.Salt + password);
admin.Update();
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "创建管理员账户时发生错误:" + ex.Message;
return Json(tip);
}
} }
//写入Lock文件 //写入Lock文件
System.IO.File.WriteAllText(lockPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); try
{
System.IO.File.WriteAllText(lockPath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
catch (Exception ex)
{
NewLife.Log.XTrace.WriteException(ex);
tip.Message = "创建安装锁文件时发生错误:" + ex.Message;
return Json(tip);
}
tip.Message = "导入数据成功!"; tip.Message = "导入数据成功!";
tip.Status = JsonTip.SUCCESS; tip.Status = JsonTip.SUCCESS;
tip.ReturnUrl = "/"; tip.ReturnUrl = "/";
return Json(tip); return Json(tip);
} }
#endregion #endregion
#region 测试 #region 测试
//[Route("c/{*path}/index2.html")] //[Route("c/{*path}/index2.html")]
//public IActionResult Test(string path = "") //public IActionResult Test(string path = "")
//{ //{
@@ -228,10 +291,12 @@ namespace COMCMS.Web.Controllers
//{ //{
// return View(); // return View();
//} //}
#endregion #endregion
#region 系统文章栏目、商品栏目路由 #region 系统文章栏目、商品栏目路由
/// <summary> /// <summary>
/// 一级路径栏目 /// 一级路径栏目
/// </summary> /// </summary>
@@ -240,24 +305,26 @@ namespace COMCMS.Web.Controllers
[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index.html")] [Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index.html")]
[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] [Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path,int page=1) public IActionResult ShowCategory(string path, int page = 1)
{ {
//先判断文章栏目 //先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path); ArticleCategory articleCategory = ArticleCategory.FindByFilePath("/" + path);
if(articleCategory != null) if (articleCategory != null)
{ {
//return Content(articleCategory.Id.ToString()); //return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath("/" + path); Category category = Category.FindByFilePath("/" + path);
if(category != null) if (category != null)
{ {
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id,page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!"+"/"+path);
return EchoTip("系统找不到本栏目!" + "/" + path);
} }
/// <summary> /// <summary>
@@ -279,6 +346,7 @@ namespace COMCMS.Web.Controllers
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -286,15 +354,19 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + path + "|" + path2); return EchoTip("系统找不到本栏目!" + path + "|" + path2);
} }
/// <summary> /// <summary>
/// 三级路径栏目 /// 三级路径栏目
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index.html")] [Route(
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] "{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index.html")]
[Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, int page = 1) public IActionResult ShowCategory(string path, string path2, string path3, int page = 1)
{ {
@@ -307,6 +379,7 @@ namespace COMCMS.Web.Controllers
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -314,15 +387,19 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + fullPath); return EchoTip("系统找不到本栏目!" + fullPath);
} }
/// <summary> /// <summary>
/// 四级路径栏目 /// 四级路径栏目
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <returns></returns> /// <returns></returns>
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index.html")] [Route(
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")] "{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index.html")]
[Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
//[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/")] //[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, string path4, int page = 1) public IActionResult ShowCategory(string path, string path2, string path3, string path4, int page = 1)
{ {
@@ -333,8 +410,9 @@ namespace COMCMS.Web.Controllers
{ {
//return Content(articleCategory.Id.ToString()); //return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id,page); return ac.Index(articleCategory.Id, page);
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -342,11 +420,14 @@ namespace COMCMS.Web.Controllers
ProductController pc = new ProductController(); ProductController pc = new ProductController();
return pc.Index(category.Id, page); return pc.Index(category.Id, page);
} }
return EchoTip("系统找不到本栏目!" + fullPath); return EchoTip("系统找不到本栏目!" + fullPath);
} }
#endregion #endregion
#region 文章详情、商品详情 #region 文章详情、商品详情
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -368,17 +449,20 @@ namespace COMCMS.Web.Controllers
{ {
article = Article.FindById(int.Parse(filename)); article = Article.FindById(int.Parse(filename));
} }
if (article == null) if (article == null)
{ {
filename = filename + ".html"; filename = filename + ".html";
article = Article.FindByFileName(filename, articleCategory.Id); article = Article.FindByFileName(filename, articleCategory.Id);
} }
if(article != null)
if (article != null)
{ {
ArticleController ac = new ArticleController(); ArticleController ac = new ArticleController();
return ac.Detail(article.Id); return ac.Detail(article.Id);
} }
} }
//再判断商品 //再判断商品
Category category = Category.FindByFilePath(fullPath); Category category = Category.FindByFilePath(fullPath);
if (category != null) if (category != null)
@@ -389,11 +473,13 @@ namespace COMCMS.Web.Controllers
{ {
product = Product.FindById(int.Parse(filename)); product = Product.FindById(int.Parse(filename));
} }
if (product == null) if (product == null)
{ {
filename = filename + ".html"; filename = filename + ".html";
product = Product.FindByFileName(filename, articleCategory.Id); product = Product.FindByFileName(filename, articleCategory.Id);
} }
if (product != null) if (product != null)
{ {
ProductController pc = new ProductController(); ProductController pc = new ProductController();
@@ -403,6 +489,7 @@ namespace COMCMS.Web.Controllers
return EchoTip("系统找不到本详情!" + "/" + path + "/" + filename); return EchoTip("系统找不到本详情!" + "/" + path + "/" + filename);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -410,12 +497,14 @@ namespace COMCMS.Web.Controllers
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string filename) public IActionResult ShowDetail(string path, string path2, string filename)
{ {
string fullPath = $"{path}/{path2}"; string fullPath = $"{path}/{path2}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -423,23 +512,28 @@ namespace COMCMS.Web.Controllers
/// <param name="filename"></param> /// <param name="filename"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string path3, string filename) public IActionResult ShowDetail(string path, string path2, string path3, string filename)
{ {
string fullPath = $"{path}/{path2}/{path3}"; string fullPath = $"{path}/{path2}/{path3}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
//四级 //四级
[HttpGet] [HttpGet]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")] [Route(
"{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/{path3:regex(^[[a-zA-Z0-9-]]+$)}/{path4:regex(^[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string path2, string path3, string path4, string filename) public IActionResult ShowDetail(string path, string path2, string path3, string path4, string filename)
{ {
string fullPath = $"{path}/{path2}/{path3}/{path4}"; string fullPath = $"{path}/{path2}/{path3}/{path4}";
return ShowDetail(fullPath, filename); return ShowDetail(fullPath, filename);
} }
#endregion #endregion
#region sitemap html #region sitemap html
[Route("sitemap.html")] [Route("sitemap.html")]
[HttpGet] [HttpGet]
public IActionResult SitemapHTML() public IActionResult SitemapHTML()
@@ -447,9 +541,11 @@ namespace COMCMS.Web.Controllers
ViewBag.cfg = cfg; ViewBag.cfg = cfg;
return View(); return View();
} }
#endregion #endregion
#region sitemap xml #region sitemap xml
[HttpGet] [HttpGet]
[Route("sitemap.xml")] [Route("sitemap.xml")]
public IActionResult SitemapXML() public IActionResult SitemapXML()
@@ -457,9 +553,11 @@ namespace COMCMS.Web.Controllers
Response.ContentType = "text/xml"; Response.ContentType = "text/xml";
return View(); return View();
} }
#endregion #endregion
#region 测试 #region 测试
public IActionResult Test() public IActionResult Test()
{ {
//至少八个字符,至少一个字母和一个数字 //至少八个字符,至少一个字母和一个数字
@@ -475,7 +573,6 @@ namespace COMCMS.Web.Controllers
bool t6 = Regex.IsMatch("123456vW@", rgx2); bool t6 = Regex.IsMatch("123456vW@", rgx2);
string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}"; string result = $"t1:{t1}; t2:{t2}; t3:{t3}; t4:{t4}; t5:{t5}; t6:{t6}";
@@ -483,9 +580,9 @@ namespace COMCMS.Web.Controllers
string a = _cacheProvider.Cache.Get<string>("test"); string a = _cacheProvider.Cache.Get<string>("test");
return Content(result+";cache:"+ a); return Content(result + ";cache:" + a);
} }
#endregion #endregion
} }
} }
+1 -1
View File
@@ -15,7 +15,7 @@
- [ ] 代码质量与可维护性 - [ ] 代码质量与可维护性
- [ ] 3.1 重复代码 - 提取公共方法处理栏目和详情查找逻辑 - [ ] 3.1 重复代码 - 提取公共方法处理栏目和详情查找逻辑
- [ ] 3.2 魔法字符串和数字 - 使用常量或枚举替代魔法值 - [ ] 3.2 魔法字符串和数字 - 使用常量或枚举替代魔法值
- [ ] 3.3 异常处理 - 为关键操作添加异常处理机制 - [x] 3.3 异常处理 - 为关键操作添加异常处理机制
- [x] 3.4 配置管理 - 将硬编码的配置项移至 appsettings.json - [x] 3.4 配置管理 - 将硬编码的配置项移至 appsettings.json
- [ ] 架构与设计 - [ ] 架构与设计