完善伪静态链接

This commit is contained in:
2020-05-09 19:37:40 +08:00
parent 1642536afd
commit 643ef876a0
66 changed files with 4490 additions and 4163 deletions
@@ -42,12 +42,16 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
var asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (var asmItem in asms)
{
var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
if (types.Count == 0) continue;
foreach (var type in types)
string fullName = asmItem.GetName().ToString();
if (fullName.IndexOf("COMCMS.Web.Views") > -1)
{
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
listTpls.Add(viewName);
var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
if (types.Count == 0) continue;
foreach (var type in types)
{
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
listTpls.Add(viewName);
}
}
}
ViewBag.ListTpl = listTpls;
@@ -120,12 +124,16 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
var asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (var asmItem in asms)
{
var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
if (types.Count == 0) continue;
foreach (var type in types)
string fullName = asmItem.GetName().ToString();
if (fullName.IndexOf("COMCMS.Web.Views") > -1)
{
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
listTpls.Add(viewName);
var types = asmItem.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
if (types.Count == 0) continue;
foreach (var type in types)
{
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
listTpls.Add(viewName);
}
}
}
ViewBag.ListTpl = listTpls;
@@ -387,6 +395,11 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "文章图片填写的不是图片格式!";
return Json(tip);
}
if (!string.IsNullOrEmpty(model.FileName) && !Utils.ChekHTMLFileNameIsOK(model.FileName))
{
tip.Message = "静态化文件名错误,请填写正确的,或者留空!";
return Json(tip);
}
//处理文章更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -470,6 +483,12 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
tip.Message = "文章图片填写的不是图片格式!";
return Json(tip);
}
//处理
if (!string.IsNullOrEmpty(model.FileName) && !Utils.ChekHTMLFileNameIsOK(model.FileName))
{
tip.Message = "静态化文件名错误,请填写正确的,或者留空!";
return Json(tip);
}
//处理文章更多图片
string[] moreImgSrc = Request.Form["nImgUrl"];
string morIMG = string.Empty;//更多图片的时候用到
@@ -537,6 +556,7 @@ namespace COMCMS.Web.Areas.AdminCP.Controllers
entity.Title = model.Title;
entity.TitleColor = model.TitleColor;
entity.UpdateTime = DateTime.Now;
entity.FileName = model.FileName;
//model.AuthorId = Core.Admin.GetMyInfo().Id;
entity.Update();
@@ -30,6 +30,12 @@
<input id="Title" name="Title" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写文章标题">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">静态化文件名:</label>
<div class="col-sm-8">
<input id="FileName" name="FileName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写静态化文件名,大小写字母、数字和-,如:about.html,不能是index.html" value="">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">副标题:</label>
<div class="col-sm-8">
@@ -29,6 +29,12 @@
<input id="Title" name="Title" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写文章标题" value="@Model.Title">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">静态化文件名:</label>
<div class="col-sm-8">
<input id="FileName" name="FileName" maxlength="200" type="text" class="form-control" required aria-required="true" placeholder="填写静态化文件名,大小写字母、数字和-,如:about.html,不能是index.html" value="@Model.FileName">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">副标题:</label>
<div class="col-sm-8">
+6 -9
View File
@@ -9,15 +9,15 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
<PackageReference Include="MimeKit" Version="2.6.0" />
<PackageReference Include="MySql.Data" Version="8.0.19" />
<PackageReference Include="NewLife.XCode" Version="9.16.2020.403" />
<PackageReference Include="MySql.Data" Version="8.0.20" />
<PackageReference Include="NewLife.XCode" Version="9.17.2020.501" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Senparc.NeuChar" Version="1.2.106" />
<PackageReference Include="Senparc.Weixin" Version="6.7.500" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.10.500" />
<PackageReference Include="Senparc.Weixin" Version="6.7.502" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.10.502" />
<PackageReference Include="Senparc.Weixin.MP.MvcExtension" Version="4.1.1" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.5.500" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.8.501" />
<PackageReference Include="Senparc.Weixin.TenPay" Version="1.5.502" />
<PackageReference Include="Senparc.Weixin.WxOpen" Version="3.8.502" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
<PackageReference Include="ZKWeb.System.Drawing" Version="4.0.1" />
</ItemGroup>
@@ -288,9 +288,6 @@
</ItemGroup>
<ItemGroup>
<Content Update="app.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
+28 -2
View File
@@ -23,7 +23,7 @@ namespace COMCMS.Web.Common
public static string EchoURL(ArticleCategory model)
{
if (model == null)
return "";
return "javascript:;";
if (!string.IsNullOrEmpty(model.FilePath))
return model.FilePath + "/index.html";
else
@@ -37,7 +37,7 @@ namespace COMCMS.Web.Common
public static string EchoURL(Category model)
{
if (model == null)
return "";
return "javascript:;";
if (!string.IsNullOrEmpty(model.FilePath))
return model.FilePath + "/index.html";
else
@@ -71,5 +71,31 @@ namespace COMCMS.Web.Common
}
#endregion
#region 生成详情地址
/// <summary>
/// 生成文章详情地址
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static string EchoArticleURL(Article model)
{
if (model == null)
return "javascript:;";
if (!string.IsNullOrEmpty(model.ArticleKind.FilePath))
{
string url = $"{model.ArticleKind.FilePath}/{model.Id}.html";
if (!string.IsNullOrEmpty(model.FileName))
{
url = $"{model.ArticleKind.FilePath}/{model.FileName}";
}
return url;
}
else
return $"/article/detail/{model.Id}";
}
#endregion
}
}
+3 -3
View File
@@ -139,9 +139,9 @@ namespace COMCMS.Web.Controllers
}
string templatesname = "";//模板名称
if (!string.IsNullOrEmpty(kind.TemplateFile))
{
templatesname = kind.DetailTemplateFile.Replace(".cshtml", "").Replace(".aspx", "");
return View(templatesname, entity);
{
templatesname = kind.DetailTemplateFile;//.Replace(".cshtml", "").Replace(".aspx", "");
return View("~/Views/Article/" + templatesname, entity);
}
else
{
+204 -9
View File
@@ -186,11 +186,27 @@ namespace COMCMS.Web.Controllers
#region 测试
//[Route("c/{*path}/index2.html")]
//public IActionResult Test(string path = "")
//{
// string tel = "13332835377";
// return Content(tel.Substring(tel.Length - 5) + ";path:" + path);
//}
public IActionResult Test(string path = "")
{
var asms = AppDomain.CurrentDomain.GetAssemblies();
List<string> list = new List<string>();
foreach (var item in asms)
{
string fullName = item.GetName().ToString();
if (fullName.IndexOf("COMCMS.Web.Views")>-1)
{
var types = item.GetTypes().Where(e => e.Name.StartsWith("Views_Article")).ToList();
foreach (var type in types)
{
string viewName = type.Name.Replace("Views_Article_", "") + ".cshtml";
list.Add(viewName);
}
}
//list.Add(item.GetName().ToString());
}
return Content(JsonConvert.SerializeObject(list));
}
//[Route("{path1:regex([[a-zA-Z0-9-]])}/{path2:regex([[a-zA-Z0-9-]])}/index.html")]
//public IActionResult Test2(string path1 = "", string path2 = "")
//{
@@ -207,9 +223,9 @@ namespace COMCMS.Web.Controllers
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[Route("{path:regex([[a-zA-Z0-9-]])}/index.html")]
[Route("{path:regex([[a-zA-Z0-9-]])}/index-{page:int}.html")]
[Route("{path:regex([[a-zA-Z0-9-]])}/")]
[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-]]+$)}/")]
public IActionResult ShowCategory(string path,int page=1)
{
//先判断文章栏目
@@ -218,7 +234,7 @@ namespace COMCMS.Web.Controllers
{
//return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id);
return ac.Index(articleCategory.Id, page);
}
//再判断商品
Category category = Category.FindByFilePath("/" + path);
@@ -229,7 +245,186 @@ namespace COMCMS.Web.Controllers
}
return EchoTip("系统找不到本栏目!"+"/"+path);
}
/// <summary>
/// 二级路径栏目
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/index.html")]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/index-{page:int}.html")]
[Route("{path:regex(^[[a-zA-Z0-9-]]+$)}/{path2:regex(^[[a-zA-Z0-9-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, int page = 1)
{
string fullPath = $"/{path}/{path2}";
//先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath(fullPath);
if (articleCategory != null)
{
//return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page);
}
//再判断商品
Category category = Category.FindByFilePath(fullPath);
if (category != null)
{
ProductController pc = new ProductController();
return pc.Index(category.Id, page);
}
return EchoTip("系统找不到本栏目!" + path + "|" + path2);
}
/// <summary>
/// 三级路径栏目
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[Route("{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-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, int page = 1)
{
string fullPath = $"/{path}/{path2}/{path3}";
//先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath(fullPath);
if (articleCategory != null)
{
//return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id, page);
}
//再判断商品
Category category = Category.FindByFilePath(fullPath);
if (category != null)
{
ProductController pc = new ProductController();
return pc.Index(category.Id, page);
}
return EchoTip("系统找不到本栏目!" + fullPath);
}
/// <summary>
/// 四级路径栏目
/// </summary>
/// <param name="path"></param>
/// <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("{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-]]+$)}/")]
public IActionResult ShowCategory(string path, string path2, string path3, string path4, int page = 1)
{
string fullPath = $"/{path}/{path2}/{path3}/{path4}";
//先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath(fullPath);
if (articleCategory != null)
{
//return Content(articleCategory.Id.ToString());
ArticleController ac = new ArticleController();
return ac.Index(articleCategory.Id,page);
}
//再判断商品
Category category = Category.FindByFilePath(fullPath);
if (category != null)
{
ProductController pc = new ProductController();
return pc.Index(category.Id, page);
}
return EchoTip("系统找不到本栏目!" + fullPath);
}
#endregion
#region 文章详情、商品详情
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <returns></returns>
[HttpGet]
[Route("{path:regex(^(?!swagger\\b)[[a-zA-Z0-9-]]+$)}/{filename:regex(^(?!index\\b)[[a-zA-Z0-9-]]+$)}.html")]
public IActionResult ShowDetail(string path, string filename)
{
string fullPath = $"/{path}";
//先判断文章栏目
ArticleCategory articleCategory = ArticleCategory.FindByFilePath(fullPath);
if (articleCategory != null)
{
Article article = null;
//判断文件名
if (Utils.IsInt(filename))
{
article = Article.FindById(int.Parse(filename));
}
if (article == null)
{
filename = filename + ".html";
article = Article.FindByFileName(filename, articleCategory.Id);
}
if(article != null)
{
ArticleController ac = new ArticleController();
return ac.Detail(article.Id);
}
}
//再判断商品
Category category = Category.FindByFilePath(fullPath);
if (category != null)
{
Product product = null;
//判断文件名
if (Utils.IsInt(filename))
{
product = Product.FindById(int.Parse(filename));
}
if (product == null)
{
filename = filename + ".html";
product = Product.FindByFileName(filename, articleCategory.Id);
}
if (product != null)
{
ProductController pc = new ProductController();
return pc.Detail(product.Id);
}
}
return EchoTip("系统找不到本详情!" + "/" + path + "/" + filename);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <returns></returns>
[HttpGet]
[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)
{
string fullPath = $"{path}/{path2}";
return ShowDetail(fullPath, filename);
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <returns></returns>
[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")]
public IActionResult ShowDetail(string path, string path2, string path3, string filename)
{
string fullPath = $"{path}/{path2}/{path3}";
return ShowDetail(fullPath, filename);
}
//四级
[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")]
public IActionResult ShowDetail(string path, string path2, string path3, string path4, string filename)
{
string fullPath = $"{path}/{path2}/{path3}/{path4}";
return ShowDetail(fullPath, filename);
}
#endregion
}
}
+16 -8
View File
@@ -151,16 +151,24 @@ namespace COMCMS.Web
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "article",
pattern: "{title}/index.html",
defaults: new { controller = "Home", action = "Article" }
);
endpoints.MapControllerRoute(
name: "article2",
pattern: "{title}/",
defaults: new { controller = "Home", action = "Article" }
name: "index",
pattern: "/index.html",
defaults: new { controller = "Home", action = "Index" }
);
//endpoints.MapControllerRoute(
//name: "article",
//pattern: "{title}/index.html",
//defaults: new { controller = "Home", action = "Article" }
//);
//endpoints.MapControllerRoute(
//name: "article2",
//pattern: "{title}/",
//defaults: new { controller = "Home", action = "Article" }
//);
});
//使用环境变量
+1 -1
View File
@@ -33,7 +33,7 @@
<ul class="sec-nav-list">
@foreach (Article a in alist)
{
<li class="@(a.Id == Model.Id?"sec-on":"")"><a asp-controller="Article" asp-action="Detail" asp-route-id="@(a.Id)" title="@a.Title">@a.Title</a></li>
<li class="@(a.Id == Model.Id?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@a.Title">@a.Title</a></li>
}
</ul>
+1 -1
View File
@@ -32,7 +32,7 @@
<ul class="sec-nav-list">
@foreach (Article a in alist)
{
<li class="@(a.Id == Model.Id?"sec-on":"")"><a asp-controller="Article" asp-action="Detail" asp-route-id="@(a.Id)" title="@a.Title">@a.Title</a></li>
<li class="@(a.Id == Model.Id?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@a.Title">@a.Title</a></li>
}
</ul>
@@ -35,7 +35,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.KId?"sec-on":"")"><a asp-controller="Article" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.KId?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
+1 -1
View File
@@ -35,7 +35,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.KId?"sec-on":"")"><a asp-controller="Article" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.KId?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
+2 -2
View File
@@ -36,7 +36,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.Id?"sec-on":"")"><a asp-controller="Article" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.Id?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
@@ -63,7 +63,7 @@
@foreach (Article a in ViewBag.list)
{
<li>
<a asp-controller="Article" asp-action="Detail" asp-route-id="@(a.Id)" title="@a.Title">
<a href="@ViewsHelper.EchoArticleURL(a)" title="@a.Title">
@if (!string.IsNullOrEmpty(a.Pic))
{
<div class="news-pic">
@@ -35,7 +35,7 @@
<ul class="sec-nav-list">
@foreach (var k in sameList)
{
<li class="@(k.Id == Model.Id?"sec-on":"")"><a asp-controller="Article" asp-action="Index" asp-route-id="@(k.Id)" title="@k.KindName">@k.KindName</a></li>
<li class="@(k.Id == Model.Id?"sec-on":"")"><a href="@ViewsHelper.EchoURL(k)" title="@k.KindName">@k.KindName</a></li>
}
</ul>
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- 加密盐值 对应小程序也要填写一样的 -->
<add key="SignSalt" value="mycomcms" />
</appSettings>
<connectionStrings>
<!--<add name="dbconn" connectionString="Server=.;Port=3306;Database=comcmscore;Uid=root;Pwd=root;SslMode=None" providerName="MySql.Data.MySqlClient" />-->
<!--<add name="dbconn" connectionString="server=(local);database=comcmscore;uid=sa;pwd=123456" providerName="System.Data.SqlClient" />-->
<!--<add name="dbconn" connectionString="Data Source=~/App_Data/ratuodb.db" providerName="Sqlite" />-->
</connectionStrings>
</configuration>