ソースを参照

redis库更换为CSRedis

懒得勤快 6 年 前
コミット
22a2f5a871
35 ファイル変更376 行追加270 行削除
  1. 3 9
      src/Masuit.MyBlogs.Core/Common/CommonHelper.cs
  2. 1 7
      src/Masuit.MyBlogs.Core/Controllers/BaseController.cs
  3. 0 1
      src/Masuit.MyBlogs.Core/Controllers/BugController.cs
  4. 3 3
      src/Masuit.MyBlogs.Core/Controllers/CommentController.cs
  5. 1 1
      src/Masuit.MyBlogs.Core/Controllers/HomeController.cs
  6. 0 1
      src/Masuit.MyBlogs.Core/Controllers/LinksController.cs
  7. 0 1
      src/Masuit.MyBlogs.Core/Controllers/MiscController.cs
  8. 0 1
      src/Masuit.MyBlogs.Core/Controllers/MsgController.cs
  9. 5 5
      src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs
  10. 1 1
      src/Masuit.MyBlogs.Core/Controllers/PassportController.cs
  11. 10 10
      src/Masuit.MyBlogs.Core/Controllers/PostController.cs
  12. 36 41
      src/Masuit.MyBlogs.Core/Controllers/SearchController.cs
  13. 0 1
      src/Masuit.MyBlogs.Core/Controllers/SeminarController.cs
  14. 13 12
      src/Masuit.MyBlogs.Core/Controllers/SystemController.cs
  15. 1 1
      src/Masuit.MyBlogs.Core/Controllers/ToolsController.cs
  16. 1 1
      src/Masuit.MyBlogs.Core/Controllers/UploadController.cs
  17. 0 1
      src/Masuit.MyBlogs.Core/Extensions/AuthorityAttribute.cs
  18. 3 7
      src/Masuit.MyBlogs.Core/Extensions/FirewallMiddleware.cs
  19. 5 13
      src/Masuit.MyBlogs.Core/Extensions/Hangfire/HangfireBackJob.cs
  20. 2 6
      src/Masuit.MyBlogs.Core/Extensions/RequestInterceptMiddleware.cs
  21. 135 0
      src/Masuit.MyBlogs.Core/Extensions/SessionExt.cs
  22. 4 2
      src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj
  23. 6 2
      src/Masuit.MyBlogs.Core/Startup.cs
  24. 2 3
      src/Masuit.MyBlogs.Core/Views/Home/Category.cshtml
  25. 1 1
      src/Masuit.MyBlogs.Core/Views/Home/Index.cshtml
  26. 1 1
      src/Masuit.MyBlogs.Core/Views/Home/Post.cshtml
  27. 1 1
      src/Masuit.MyBlogs.Core/Views/Home/Tag.cshtml
  28. 1 1
      src/Masuit.MyBlogs.Core/Views/Msg/Index_Admin.cshtml
  29. 1 1
      src/Masuit.MyBlogs.Core/Views/Notice/Details.cshtml
  30. 1 1
      src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml
  31. 1 1
      src/Masuit.MyBlogs.Core/Views/Post/Details_Admin.cshtml
  32. 129 125
      src/Masuit.MyBlogs.Core/Views/Post/HistoryVersion.cshtml
  33. 6 6
      src/Masuit.MyBlogs.Core/Views/Post/Publish_Admin.cshtml
  34. 1 1
      src/Masuit.MyBlogs.Core/Views/Seminar/Index.cshtml
  35. 1 1
      src/Masuit.MyBlogs.Core/Views/Shared/_Layout.cshtml

+ 3 - 9
src/Masuit.MyBlogs.Core/Common/CommonHelper.cs

@@ -13,7 +13,6 @@ using Masuit.Tools.Media;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools.Models;
 #endif
-using Masuit.Tools.NoSQL;
 using Masuit.Tools.Security;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Net.Http.Headers;
@@ -94,10 +93,7 @@ namespace Common
             {
                 try
                 {
-                    using (var redisHelper = RedisHelper.GetInstance())
-                    {
-                        return redisHelper.GetString<double>("Interview:ViewCount");
-                    }
+                    return RedisHelper.Get<double>("Interview:ViewCount");
                 }
                 catch
                 {
@@ -115,10 +111,8 @@ namespace Common
             {
                 try
                 {
-                    using (var redisHelper = RedisHelper.GetInstance())
-                    {
-                        return redisHelper.GetString<double>("Interview:ViewCount") / redisHelper.GetString<double>("Interview:RunningDays");
-                    }
+                    return RedisHelper.Get<double>("Interview:ViewCount") / RedisHelper.Get<double>("Interview:RunningDays");
+
                 }
                 catch
                 {

+ 1 - 7
src/Masuit.MyBlogs.Core/Controllers/BaseController.cs

@@ -1,10 +1,9 @@
 using Masuit.MyBlogs.Core.Configs;
+using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
-using Masuit.Tools.NoSQL;
 using Masuit.Tools.Security;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -43,11 +42,6 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// </summary>
         public ILinksService LinksService { get; set; }
 
-        /// <summary>
-        /// RedisHelper
-        /// </summary>
-        public RedisHelper RedisHelper { get; set; }
-
         /// <summary>
         /// 响应数据
         /// </summary>

+ 0 - 1
src/Masuit.MyBlogs.Core/Controllers/BugController.cs

@@ -9,7 +9,6 @@ using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.RequestModels;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;

+ 3 - 3
src/Masuit.MyBlogs.Core/Controllers/CommentController.cs

@@ -6,7 +6,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;
@@ -17,6 +16,7 @@ using System.IO;
 using System.Linq;
 using System.Text.RegularExpressions;
 using System.Web;
+using Microsoft.AspNetCore.Http;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -164,7 +164,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult CommentVote(int id)
         {
             Comment cm = CommentService.GetFirstEntity(c => c.Id == id && c.Status == Status.Pended);
-            if (HttpContext.Session.Get<object>("cm" + id) != null)
+            if (HttpContext.Session.Get("cm" + id) != null)
             {
                 return ResultData(null, false, "您刚才已经投过票了,感谢您的参与!");
             }
@@ -172,7 +172,7 @@ namespace Masuit.MyBlogs.Core.Controllers
             {
                 cm.VoteCount++;
                 CommentService.UpdateEntity(cm);
-                HttpContext.Session.Set("cm" + id, id);
+                HttpContext.Session.Set("cm" + id, id.GetBytes());
                 bool b = CommentService.SaveChanges() > 0;
                 return ResultData(null, b, b ? "投票成功" : "投票失败");
             }

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/HomeController.cs

@@ -1,12 +1,12 @@
 using AutoMapper.QueryableExtensions;
 using EFSecondLevelCache.Core;
+using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
-using Masuit.Tools.Core.Net;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Net.Http.Headers;
 using System;

+ 0 - 1
src/Masuit.MyBlogs.Core/Controllers/LinksController.cs

@@ -5,7 +5,6 @@ using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
-using Masuit.Tools.Core.Net;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Net.Http.Headers;
 using System;

+ 0 - 1
src/Masuit.MyBlogs.Core/Controllers/MiscController.cs

@@ -5,7 +5,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;

+ 0 - 1
src/Masuit.MyBlogs.Core/Controllers/MsgController.cs

@@ -6,7 +6,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;

+ 5 - 5
src/Masuit.MyBlogs.Core/Controllers/NoticeController.cs

@@ -6,7 +6,6 @@ using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;
@@ -15,6 +14,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -176,11 +176,11 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult Get(int id)
         {
             Notice notice = NoticeService.GetById(id);
-            if (HttpContext.Session.Get<object>("notice" + id) is null)
+            if (HttpContext.Session.Get("notice" + id) is null)
             {
                 notice.ViewCount++;
                 NoticeService.UpdateEntitySaved(notice);
-                HttpContext.Session.Set("notice" + id, id);
+                HttpContext.Session.Set("notice" + id, id.GetBytes());
             }
             return ResultData(notice.MapTo<NoticeOutputDto>());
         }
@@ -195,11 +195,11 @@ namespace Masuit.MyBlogs.Core.Controllers
             var notice = NoticeService.GetFirstEntity(n => n.Status == Status.Display, n => n.ModifyDate, false);
             if (notice != null)
             {
-                if (HttpContext.Session.Get<object>("notice" + notice.Id) is null)
+                if (HttpContext.Session.Get("notice" + notice.Id) is null)
                 {
                     notice.ViewCount++;
                     NoticeService.UpdateEntitySaved(notice);
-                    HttpContext.Session.Set("notice" + notice.Id, notice.Id);
+                    HttpContext.Session.Set("notice" + notice.Id, notice.Id.GetBytes());
                 }
                 return ResultData(notice.Mapper<NoticeOutputDto>());
             }

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/PassportController.cs

@@ -1,6 +1,7 @@
 using Common;
 using Masuit.MyBlogs.Core.Common;
 using Masuit.MyBlogs.Core.Configs;
+using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Extensions.Hangfire;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
@@ -8,7 +9,6 @@ using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
 using Masuit.Tools.AspNetCore.ResumeFileResults.Extensions;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Security;
 using Masuit.Tools.Strings;
 using Microsoft.AspNetCore.Hosting;

+ 10 - 10
src/Masuit.MyBlogs.Core/Controllers/PostController.cs

@@ -14,7 +14,6 @@ using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.DateTimeExt;
 using Masuit.Tools.Html;
 using Masuit.Tools.Security;
@@ -28,6 +27,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
 
 namespace Masuit.MyBlogs.Core.Controllers
 {
@@ -210,14 +210,14 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult VoteDown(int id)
         {
             Post post = PostService.GetById(id);
-            if (HttpContext.Session.Get<object>("post-vote" + id) != null)
+            if (HttpContext.Session.Get("post-vote" + id) != null)
             {
                 return ResultData(null, false, "您刚才已经投过票了,感谢您的参与!");
             }
 
             if (post != null)
             {
-                HttpContext.Session.Set("post-vote" + id, id);
+                HttpContext.Session.Set("post-vote" + id, id.GetBytes());
                 ++post.VoteDownCount;
                 PostService.UpdateEntity(post);
                 var b = PostService.SaveChanges() > 0;
@@ -235,14 +235,14 @@ namespace Masuit.MyBlogs.Core.Controllers
         public ActionResult VoteUp(int id)
         {
             Post post = PostService.GetById(id);
-            if (HttpContext.Session.Get<object>("post-vote" + id) != null)
+            if (HttpContext.Session.Get("post-vote" + id) != null)
             {
                 return ResultData(null, false, "您刚才已经投过票了,感谢您的参与!");
             }
 
             if (post != null)
             {
-                HttpContext.Session.Set("post-vote" + id, id);
+                HttpContext.Session.Set("post-vote" + id, id.GetBytes());
                 ++post.VoteUpCount;
                 PostService.UpdateEntity(post);
                 var b = PostService.SaveChanges() > 0;
@@ -410,7 +410,7 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return ResultData(null, false, "请输入文章访问密码!");
             }
 
-            var s = RedisHelper.GetString("ArticleViewToken");
+            var s = RedisHelper.Get("ArticleViewToken");
             if (token.Equals(s))
             {
                 HttpContext.Session.SetByRedis("ArticleViewToken", token);
@@ -435,7 +435,7 @@ namespace Masuit.MyBlogs.Core.Controllers
 
             if (BroadcastService.Any(b => b.Email.Equals(email) && b.SubscribeType == SubscribeType.ArticleToken))
             {
-                var s = RedisHelper.GetString("ArticleViewToken");
+                var s = RedisHelper.Get("ArticleViewToken");
                 HttpContext.Session.SetByRedis("ArticleViewToken", s);
                 return ResultData(null);
             }
@@ -1093,12 +1093,12 @@ namespace Masuit.MyBlogs.Core.Controllers
         [Authority, HttpPost]
         public ActionResult ViewToken()
         {
-            if (!RedisHelper.KeyExists("ArticleViewToken"))
+            if (!RedisHelper.Exists("ArticleViewToken"))
             {
-                RedisHelper.SetString("ArticleViewToken", string.Empty.CreateShortToken(6));
+                RedisHelper.Set("ArticleViewToken", string.Empty.CreateShortToken(6));
             }
 
-            var token = RedisHelper.GetString("ArticleViewToken");
+            var token = RedisHelper.Get("ArticleViewToken");
             return ResultData(token);
         }
 

+ 36 - 41
src/Masuit.MyBlogs.Core/Controllers/SearchController.cs

@@ -5,9 +5,6 @@ using Masuit.MyBlogs.Core.Infrastructure.Application;
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
-using Masuit.Tools;
-using Masuit.Tools.Core.Net;
-using Masuit.Tools.NoSQL;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Net.Http.Headers;
 using System;
@@ -62,51 +59,49 @@ namespace Masuit.MyBlogs.Core.Controllers
                 return RedirectToAction("Search");
             }
             var start = DateTime.Today.AddDays(-7);
-            using (RedisHelper redisHelper = RedisHelper.GetInstance())
+            string key = HttpContext.Connection.Id;
+            if (RedisHelper.Exists(key) && !RedisHelper.Get(key).Equals(wd))
             {
-                string key = HttpContext.Connection.Id;
-                if (redisHelper.KeyExists(key) && !redisHelper.GetString(key).Equals(wd))
+                var hotSearches = SearchDetailsService.LoadEntitiesFromL2CacheNoTracking(s => s.SearchTime > start, s => s.SearchTime, false).GroupBy(s => s.KeyWords.ToLower()).OrderByDescending(g => g.Count()).Take(7).Select(g => new KeywordsRankOutputDto()
                 {
-                    var hotSearches = SearchDetailsService.LoadEntitiesFromL2CacheNoTracking(s => s.SearchTime > start, s => s.SearchTime, false).GroupBy(s => s.KeyWords.ToLower()).OrderByDescending(g => g.Count()).Take(7).Select(g => new KeywordsRankOutputDto()
-                    {
-                        KeyWords = g.First().KeyWords,
-                        SearchCount = g.Count()
-                    }).ToList();
-                    ViewBag.hotSearches = hotSearches;
-                    ViewBag.ErrorMsg = "10秒内只能搜索1次!";
-                    return View(nul);
-                }
-                wd = wd.Trim().Replace("+", " ");
-                if (!string.IsNullOrWhiteSpace(wd) && !wd.Contains("锟斤拷"))
+                    KeyWords = g.First().KeyWords,
+                    SearchCount = g.Count()
+                }).ToList();
+                ViewBag.hotSearches = hotSearches;
+                ViewBag.ErrorMsg = "10秒内只能搜索1次!";
+                return View(nul);
+            }
+            wd = wd.Trim().Replace("+", " ");
+            if (!string.IsNullOrWhiteSpace(wd) && !wd.Contains("锟斤拷"))
+            {
+                if (!HttpContext.Session.TryGetValue("search:" + wd, out _) && !HttpContext.Request.IsRobot())
                 {
-                    if (!HttpContext.Session.TryGetValue("search:" + wd, out _) && !HttpContext.Request.IsRobot())
+                    SearchDetailsService.AddEntity(new SearchDetails
                     {
-                        SearchDetailsService.AddEntity(new SearchDetails
-                        {
-                            KeyWords = wd,
-                            SearchTime = DateTime.Now,
-                            IP = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString()
-                        });
-                        HttpContext.Session.Set("search:" + wd, wd);
-                    }
-                    var posts = _postService.SearchPage(page, size, wd);
-                    ViewBag.Elapsed = posts.Elapsed;
-                    ViewBag.Total = posts.Total;
-                    SearchDetailsService.SaveChanges();
-                    if (posts.Total > 1)
-                    {
-                        redisHelper.SetString(key, wd, TimeSpan.FromSeconds(10));
-                    }
-                    ViewBag.hotSearches = new List<KeywordsRankOutputDto>();
-                    return View(posts.Results);
+                        KeyWords = wd,
+                        SearchTime = DateTime.Now,
+                        IP = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString()
+                    });
+                    HttpContext.Session.Set("search:" + wd, wd.ToByteArray());
                 }
-                ViewBag.hotSearches = SearchDetailsService.LoadEntitiesFromL2CacheNoTracking(s => s.SearchTime > start, s => s.SearchTime, false).GroupBy(s => s.KeyWords.ToLower()).OrderByDescending(g => g.Count()).Take(7).Select(g => new KeywordsRankOutputDto()
+                var posts = _postService.SearchPage(page, size, wd);
+                ViewBag.Elapsed = posts.Elapsed;
+                ViewBag.Total = posts.Total;
+                SearchDetailsService.SaveChanges();
+                if (posts.Total > 1)
                 {
-                    KeyWords = g.FirstOrDefault().KeyWords,
-                    SearchCount = g.Count()
-                }).ToList();
-                return View(nul);
+                    RedisHelper.Set(key, wd);
+                    RedisHelper.Expire(key, TimeSpan.FromSeconds(10));
+                }
+                ViewBag.hotSearches = new List<KeywordsRankOutputDto>();
+                return View(posts.Results);
             }
+            ViewBag.hotSearches = SearchDetailsService.LoadEntitiesFromL2CacheNoTracking(s => s.SearchTime > start, s => s.SearchTime, false).GroupBy(s => s.KeyWords.ToLower()).OrderByDescending(g => g.Count()).Take(7).Select(g => new KeywordsRankOutputDto()
+            {
+                KeyWords = g.FirstOrDefault().KeyWords,
+                SearchCount = g.Count()
+            }).ToList();
+            return View(nul);
         }
 
         /// <summary>

+ 0 - 1
src/Masuit.MyBlogs.Core/Controllers/SeminarController.cs

@@ -5,7 +5,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Net.Http.Headers;
 using System;

+ 13 - 12
src/Masuit.MyBlogs.Core/Controllers/SystemController.cs

@@ -8,7 +8,6 @@ using Masuit.Tools;
 using Masuit.Tools.Hardware;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Models;
-using Masuit.Tools.NoSQL;
 using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
@@ -32,22 +31,15 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// </summary>
         public ISystemSettingService SystemSettingService { get; set; }
 
-        /// <summary>
-        /// Redis
-        /// </summary>
-        public RedisHelper RedisHelper { get; set; }
-
         /// <summary>
         /// 系统设置
         /// </summary>
         /// <param name="userInfoService"></param>
         /// <param name="systemSettingService"></param>
-        /// <param name="redisHelper"></param>
-        public SystemController(IUserInfoService userInfoService, ISystemSettingService systemSettingService, RedisHelper redisHelper)
+        public SystemController(IUserInfoService userInfoService, ISystemSettingService systemSettingService)
         {
             UserInfoService = userInfoService;
             SystemSettingService = systemSettingService;
-            RedisHelper = redisHelper;
         }
 
         /// <summary>
@@ -281,6 +273,15 @@ namespace Masuit.MyBlogs.Core.Controllers
             }
         }
 
+        /// <summary>
+        /// 清空性能计数器缓存
+        /// </summary>
+        /// <returns></returns>
+        public ActionResult ClearPerfCounter()
+        {
+            MyHub.PerformanceCounter.Clear();
+            return Ok();
+        }
         #region 网站防火墙
 
         /// <summary>
@@ -372,10 +373,10 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <returns></returns>
         public ActionResult InterceptLog()
         {
-            List<IpIntercepter> list = RedisHelper.ListRange<IpIntercepter>("intercept");
+            var list = RedisHelper.LRange<IpIntercepter>("intercept", 0, -1);
             return ResultData(new
             {
-                interceptCount = RedisHelper.GetString("interceptCount"),
+                interceptCount = RedisHelper.Get("interceptCount"),
                 list
             });
         }
@@ -386,7 +387,7 @@ namespace Masuit.MyBlogs.Core.Controllers
         /// <returns></returns>
         public ActionResult ClearInterceptLog()
         {
-            bool b = RedisHelper.DeleteKey("intercept");
+            bool b = RedisHelper.Del("intercept") > 0;
             return ResultData(null, b, b ? "拦截日志清除成功!" : "拦截日志清除失败!");
         }
 

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/ToolsController.cs

@@ -1,5 +1,4 @@
 using Masuit.MyBlogs.Core.Configs;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Models;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Net.Http.Headers;
@@ -11,6 +10,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Net.Http;
 using System.Threading.Tasks;
+using Masuit.Tools.Core.Net;
 
 #if DEBUG
 using Masuit.Tools.Win32;

+ 1 - 1
src/Masuit.MyBlogs.Core/Controllers/UploadController.cs

@@ -1,13 +1,13 @@
 using Common;
 using Hangfire;
 using Masuit.MyBlogs.Core.Common;
+using Masuit.MyBlogs.Core.Extensions;
 using Masuit.MyBlogs.Core.Extensions.UEditor;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools;
 using Masuit.Tools.AspNetCore.Mime;
 using Masuit.Tools.AspNetCore.ResumeFileResults.Extensions;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Html;
 using Masuit.Tools.Logging;
 using Masuit.Tools.Media;

+ 0 - 1
src/Masuit.MyBlogs.Core/Extensions/AuthorityAttribute.cs

@@ -2,7 +2,6 @@
 using Masuit.MyBlogs.Core.Infrastructure.Services.Interface;
 using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.ViewModel;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Security;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Http;

+ 3 - 7
src/Masuit.MyBlogs.Core/Extensions/FirewallMiddleware.cs

@@ -2,7 +2,6 @@
 using Hangfire;
 using Masuit.MyBlogs.Core.Extensions.Hangfire;
 using Masuit.Tools;
-using Masuit.Tools.NoSQL;
 using Microsoft.AspNetCore.Http;
 using System;
 using System.Threading.Tasks;
@@ -16,17 +15,14 @@ namespace Masuit.MyBlogs.Core.Extensions
     public class FirewallMiddleware
     {
         private readonly RequestDelegate _next;
-        private readonly RedisHelper _redisHelper;
 
         /// <summary>
         /// 构造函数
         /// </summary>
         /// <param name="next"></param>
-        /// <param name="redisHelper"></param>
-        public FirewallMiddleware(RequestDelegate next, RedisHelper redisHelper)
+        public FirewallMiddleware(RequestDelegate next)
         {
             _next = next;
-            _redisHelper = redisHelper;
         }
 
         /// <summary>
@@ -67,8 +63,8 @@ namespace Masuit.MyBlogs.Core.Extensions
                 return;
             }
 
-            var times = _redisHelper.StringIncrement("Frequency:" + context.Connection.Id);
-            _redisHelper.Expire("Frequency:" + context.Connection.Id, TimeSpan.FromMinutes(1));
+            var times = RedisHelper.IncrBy("Frequency:" + context.Connection.Id);
+            RedisHelper.Expire("Frequency:" + context.Connection.Id, TimeSpan.FromMinutes(1));
             if (times > 300)
             {
                 await context.Response.WriteAsync($"检测到您的IP({context.Connection.RemoteIpAddress})访问过于频繁,已被本站暂时禁止访问,如有疑问,请联系站长!");

+ 5 - 13
src/Masuit.MyBlogs.Core/Extensions/Hangfire/HangfireBackJob.cs

@@ -7,8 +7,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.Entity;
 using Masuit.MyBlogs.Core.Models.Enum;
 using Masuit.Tools.Core.Net;
-using Masuit.Tools.Core.NoSQL;
-using Masuit.Tools.NoSQL;
 using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Hosting;
 using System;
@@ -31,7 +29,6 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
         private readonly ISystemSettingService _settingService;
         private readonly ISearchDetailsService _searchDetailsService;
         private readonly ILinksService _linksService;
-        private readonly RedisHelper _redisHelper;
         private readonly IHttpClientFactory _httpClientFactory;
         private readonly IHostingEnvironment _hostingEnvironment;
         private readonly ISearchEngine<DataContext> _searchEngine;
@@ -44,18 +41,16 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
         /// <param name="settingService"></param>
         /// <param name="searchDetailsService"></param>
         /// <param name="linksService"></param>
-        /// <param name="redis"></param>
         /// <param name="httpClientFactory"></param>
         /// <param name="hostingEnvironment"></param>
         /// <param name="searchEngine"></param>
-        public HangfireBackJob(IUserInfoService userInfoService, IPostService postService, ISystemSettingService settingService, ISearchDetailsService searchDetailsService, ILinksService linksService, RedisHelperFactory redis, IHttpClientFactory httpClientFactory, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine)
+        public HangfireBackJob(IUserInfoService userInfoService, IPostService postService, ISystemSettingService settingService, ISearchDetailsService searchDetailsService, ILinksService linksService, IHttpClientFactory httpClientFactory, IHostingEnvironment hostingEnvironment, ISearchEngine<DataContext> searchEngine)
         {
             _userInfoService = userInfoService;
             _postService = postService;
             _settingService = settingService;
             _searchDetailsService = searchDetailsService;
             _linksService = linksService;
-            _redisHelper = redis.CreateDefault();
             _httpClientFactory = httpClientFactory;
             _hostingEnvironment = hostingEnvironment;
             _searchEngine = searchEngine;
@@ -144,11 +139,8 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
         /// <param name="s"></param>
         public static void InterceptLog(IpIntercepter s)
         {
-            using (RedisHelper redisHelper = RedisHelper.GetInstance())
-            {
-                redisHelper.StringIncrement("interceptCount");
-                redisHelper.ListLeftPush("intercept", s);
-            }
+            RedisHelper.IncrBy("interceptCount");
+            RedisHelper.LPush("intercept", s);
         }
 
         /// <summary>
@@ -157,8 +149,8 @@ namespace Masuit.MyBlogs.Core.Extensions.Hangfire
         public void EverydayJob()
         {
             CommonHelper.IPErrorTimes.RemoveWhere(kv => kv.Value < 100); //将访客访问出错次数少于100的移开
-            _redisHelper.SetString("ArticleViewToken", SnowFlake.GetInstance().GetUniqueShortId(6)); //更新加密文章的密码
-            _redisHelper.StringIncrement("Interview:RunningDays");
+            RedisHelper.Set("ArticleViewToken", SnowFlake.GetInstance().GetUniqueShortId(6)); //更新加密文章的密码
+            RedisHelper.IncrBy("Interview:RunningDays");
             DateTime time = DateTime.Now.AddMonths(-1);
             _searchDetailsService.DeleteEntitySaved(s => s.SearchTime < time);
             foreach (var p in _postService.GetAll().AsParallel())

+ 2 - 6
src/Masuit.MyBlogs.Core/Extensions/RequestInterceptMiddleware.cs

@@ -1,6 +1,5 @@
 using Common;
 using Masuit.Tools.Core.Net;
-using Masuit.Tools.NoSQL;
 using Microsoft.AspNetCore.Http;
 using System.Threading.Tasks;
 
@@ -12,17 +11,14 @@ namespace Masuit.MyBlogs.Core.Extensions
     public class RequestInterceptMiddleware
     {
         private readonly RequestDelegate _next;
-        private readonly RedisHelper _redisHelper;
 
         /// <summary>
         /// 构造函数
         /// </summary>
         /// <param name="next"></param>
-        /// <param name="redisHelper"></param>
-        public RequestInterceptMiddleware(RequestDelegate next, RedisHelper redisHelper)
+        public RequestInterceptMiddleware(RequestDelegate next)
         {
             _next = next;
-            _redisHelper = redisHelper;
         }
 
         public async Task Invoke(HttpContext context)
@@ -30,7 +26,7 @@ namespace Masuit.MyBlogs.Core.Extensions
             if (!context.Session.TryGetValue("session", out _) && !context.Request.IsRobot())
             {
                 context.Session.Set("session", 0);
-                _redisHelper.StringIncrement("Interview:ViewCount");
+                RedisHelper.IncrBy("Interview:ViewCount");
             }
             await _next.Invoke(context);
         }

+ 135 - 0
src/Masuit.MyBlogs.Core/Extensions/SessionExt.cs

@@ -0,0 +1,135 @@
+using Masuit.Tools;
+using Masuit.Tools.Core.Net;
+using Masuit.Tools.Logging;
+using Microsoft.AspNetCore.Http;
+using System;
+using System.Linq;
+
+namespace Masuit.MyBlogs.Core.Extensions
+{
+    /// <summary>
+    /// session扩展
+    /// </summary>
+    public static class SessionExt
+    {
+        /// <summary>
+        /// 将Session存到Redis,需要先在config中配置链接字符串,连接字符串在config配置文件中的ConnectionStrings节下配置,name固定为RedisHosts,值的格式:127.0.0.1:6379,allowadmin=true,若未正确配置,将按默认值“127.0.0.1:6379,allowadmin=true”进行操作,如:<br/>
+        /// &lt;connectionStrings&gt;<br/>
+        ///      &lt;add name = "RedisHosts" connectionString="127.0.0.1:6379,allowadmin=true"/&gt;<br/>
+        /// &lt;/connectionStrings&gt;
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="session"></param>
+        /// <param name="key">键</param>
+        /// <param name="obj">需要存的对象</param>
+        /// <param name="expire">过期时间,默认20分钟</param>
+        /// <returns></returns>
+        public static void SetByRedis<T>(this ISession session, string key, T obj, int expire = 20)
+        {
+            if (HttpContext2.Current is null)
+            {
+                throw new Exception("请确保此方法调用是在同步线程中执行!");
+            }
+            session?.SetString(key, obj.ToJsonString());
+
+            try
+            {
+                RedisHelper.HSet("Session:" + HttpContext2.Current.Connection.Id, key, obj); //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"
+                RedisHelper.Expire("Session:" + HttpContext2.Current.Connection.Id, TimeSpan.FromMinutes(expire));
+            }
+            catch
+            {
+                // ignored
+            }
+        }
+
+        /// <summary>
+        /// 从Redis取Session
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="_"></param>
+        /// <param name="key">键</param>
+        /// <param name="expire">过期时间,默认20分钟</param>
+        /// <returns></returns> 
+        public static T GetByRedis<T>(this ISession _, string key, int expire = 20) where T : class
+        {
+            if (HttpContext2.Current is null)
+            {
+                throw new Exception("请确保此方法调用是在同步线程中执行!");
+            }
+            T obj = default(T);
+            if (_ != null)
+            {
+                obj = _.Get<T>(key);
+            }
+
+            if (obj == default(T))
+            {
+                try
+                {
+                    var sessionKey = "Session:" + HttpContext2.Current.Connection.Id;
+                    if (RedisHelper.Exists(sessionKey) && RedisHelper.HExists(sessionKey, key))
+                    {
+                        RedisHelper.Expire(sessionKey, TimeSpan.FromMinutes(expire));
+                        return RedisHelper.HGet<T>(sessionKey, key);
+                    }
+
+                    return default(T);
+                }
+                catch
+                {
+                    return default(T);
+                }
+            }
+
+            return obj;
+        }
+
+        /// <summary>
+        /// 从Redis移除对应键的Session
+        /// </summary>
+        /// <param name="session"></param>
+        /// <param name="key"></param>
+        /// <returns></returns>
+        public static void RemoveByRedis(this ISession session, string key)
+        {
+            if (HttpContext2.Current is null)
+            {
+                throw new Exception("请确保此方法调用是在同步线程中执行!");
+            }
+
+            session?.Remove(key);
+
+            try
+            {
+                var sessionKey = "Session:" + HttpContext2.Current.Connection.Id;
+                if (RedisHelper.Exists(sessionKey) && RedisHelper.HExists(sessionKey, key))
+                {
+                    RedisHelper.HDel(sessionKey, key);
+                }
+            }
+            catch (Exception e)
+            {
+                LogManager.Error(e);
+            }
+        }
+
+        /// <summary>
+        /// Session个数
+        /// </summary>
+        /// <param name="session"></param>
+        /// <returns></returns>
+        public static int SessionCount(this ISession session)
+        {
+            try
+            {
+                return RedisHelper.Keys("Session:*").Count();
+            }
+            catch (Exception e)
+            {
+                LogManager.Error(e);
+                return 0;
+            }
+        }
+    }
+}

+ 4 - 2
src/Masuit.MyBlogs.Core/Masuit.MyBlogs.Core.csproj

@@ -64,10 +64,12 @@
   <ItemGroup>
     <PackageReference Include="Aspose.Words" Version="18.11.0" />
     <PackageReference Include="Autofac" Version="4.9.1" />
-    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.1" />
+    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
     <PackageReference Include="AutoMapper" Version="8.0.0" />
     <PackageReference Include="CacheManager.Microsoft.Extensions.Caching.Memory" Version="1.2.0" />
     <PackageReference Include="CacheManager.Serialization.Json" Version="1.2.0" />
+    <PackageReference Include="Caching.CSRedis" Version="3.0.36" />
+    <PackageReference Include="CSRedisCore" Version="3.0.39" />
     <PackageReference Include="Dapper" Version="1.50.7" />
     <PackageReference Include="EFSecondLevelCache.Core" Version="1.7.1" />
     <PackageReference Include="Hangfire" Version="1.6.22" />
@@ -82,7 +84,7 @@
     <PackageReference Include="Quartz" Version="3.0.7" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
     <PackageReference Include="WilderMinds.RssSyndication" Version="1.4.0" />
-    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.1.49" />
+    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.1.50" />
     <PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="1.8.18" />
     <PackageReference Include="Z.ExtensionMethods" Version="2.1.1" />
   </ItemGroup>

+ 6 - 2
src/Masuit.MyBlogs.Core/Startup.cs

@@ -2,6 +2,7 @@
 using Autofac.Extensions.DependencyInjection;
 using CacheManager.Core;
 using Common;
+using CSRedis;
 using EFSecondLevelCache.Core;
 using Hangfire;
 using Hangfire.Dashboard;
@@ -20,7 +21,6 @@ using Masuit.MyBlogs.Core.Models.DTO;
 using Masuit.MyBlogs.Core.Models.ViewModel;
 using Masuit.Tools.AspNetCore.Mime;
 using Masuit.Tools.Core.AspNetCore;
-using Masuit.Tools.Core.Net;
 using Masuit.Tools.Systems;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
@@ -31,6 +31,8 @@ using Microsoft.AspNetCore.Rewrite;
 using Microsoft.AspNetCore.StaticFiles;
 using Microsoft.AspNetCore.WebSockets;
 using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Caching.Distributed;
+using Microsoft.Extensions.Caching.Redis;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.WebEncoders;
@@ -120,7 +122,9 @@ namespace Masuit.MyBlogs.Core
             services.AddSession(); //注入Session
             services.AddHangfire(x => x.UseRedisStorage(AppConfig.Redis)); //配置hangfire
 
-            services.AddSevenZipCompressor().AddResumeFileResult().AddDefaultRedisHelper(AppConfig.Redis).AddSearchEngine<DataContext>(new LuceneIndexerOptions() { Path = "lucene" });// 配置7z和断点续传和Redis和Lucene搜索引擎
+            services.AddSevenZipCompressor().AddResumeFileResult().AddSearchEngine<DataContext>(new LuceneIndexerOptions() { Path = "lucene" });// 配置7z和断点续传和Redis和Lucene搜索引擎
+            RedisHelper.Initialization(new CSRedisClient(AppConfig.Redis));
+            services.AddSingleton<IDistributedCache>(new CSRedisCache(RedisHelper.Instance));
 
             //配置EF二级缓存
             services.AddEFSecondLevelCache();

+ 2 - 3
src/Masuit.MyBlogs.Core/Views/Home/Category.cshtml

@@ -1,7 +1,6 @@
-@using Masuit.MyBlogs.Core.Models.DTO
+@using Masuit.MyBlogs.Core.Extensions
+@using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
-@using Masuit.Tools.Net
 @model Masuit.MyBlogs.Core.Models.ViewModel.IndexPageViewModel
 @{
     ViewBag.Title = "分类_" + ViewBag.CategoryName;

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Home/Index.cshtml

@@ -2,7 +2,7 @@
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.Entity
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Win32
 @model Masuit.MyBlogs.Core.Models.ViewModel.IndexPageViewModel
 @{

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Home/Post.cshtml

@@ -5,7 +5,7 @@
 }
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @model IndexPageViewModel
 <div class="container">
     <ol class="cd-breadcrumb triangle">

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Home/Tag.cshtml

@@ -1,6 +1,6 @@
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @model IndexPageViewModel
 @{
     ViewBag.Title = "标签_" + ViewBag.Tag;

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Msg/Index_Admin.cshtml

@@ -1,6 +1,6 @@
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @{
     ViewBag.Title = "留言板";
     Layout = "~/Views/Shared/_Layout.cshtml";

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Notice/Details.cshtml

@@ -2,7 +2,7 @@
 @using Common
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @model Masuit.MyBlogs.Core.Models.Entity.Notice
 @{
     ViewBag.Title = Model.Title;

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Post/Details.cshtml

@@ -3,7 +3,7 @@
 @using Common
 @using Masuit.MyBlogs.Core.Models.Entity
 @using Masuit.MyBlogs.Core.Models.Enum
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Win32
 @model Masuit.MyBlogs.Core.Models.Entity.Post
 @{

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Post/Details_Admin.cshtml

@@ -4,7 +4,7 @@
 @using Masuit.MyBlogs.Core.Models.Entity
 @using Masuit.MyBlogs.Core.Models.Enum
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Systems
 @using Masuit.Tools.Win32
 @model Masuit.MyBlogs.Core.Models.Entity.Post

+ 129 - 125
src/Masuit.MyBlogs.Core/Views/Post/HistoryVersion.cshtml

@@ -2,11 +2,11 @@
 @using System.Web
 @using Common
 @using Masuit.MyBlogs.Core.Models.Entity
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Win32
 @model Masuit.MyBlogs.Core.Models.Entity.PostHistoryVersion
 @{
-    ViewBag.Title = Model.Post.Title+"于"+Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")+"的历史版本:"+Model.Title;
+    ViewBag.Title = Model.Post.Title + "于" + Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss") + "的历史版本:" + Model.Title;
     Layout = "~/Views/Shared/_Layout.cshtml";
     string[] colors = { "success", "info", "primary", "warning", "danger", "default", "primary" };
 }
@@ -16,9 +16,9 @@
     <ol class="cd-breadcrumb triangle">
         <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li>@Html.ActionLink("文章列表", "Post", "Home")</li>
-        <li>@Html.ActionLink(Model.Post.Title.Length>20?Model.Post.Title.Substring(0,20)+"...": Model.Post.Title, "Details", "Post",new{id=Model.PostId},null)</li>
-        <li>@Html.ActionLink("历史版本", "History", "Post",new{id=Model.PostId},null)</li>
-        <li class="current"><em>@(Model.Title.Length>40? Model.Title.Substring(0,40)+"...": Model.Title)</em></li>
+        <li>@Html.ActionLink(Model.Post.Title.Length > 20 ? Model.Post.Title.Substring(0, 20) + "..." : Model.Post.Title, "Details", "Post", new { id = Model.PostId }, null)</li>
+        <li>@Html.ActionLink("历史版本", "History", "Post", new { id = Model.PostId }, null)</li>
+        <li class="current"><em>@(Model.Title.Length > 40 ? Model.Title.Substring(0, 40) + "..." : Model.Title)</em></li>
     </ol>
     <div class="wrapper-content article">
         <div class="ibox">
@@ -36,17 +36,17 @@
                             <div class="row">
                                 <div class="col-sm-7">
                                     <div class="padding-bot10">
-                                        修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span> | 
-                                    原分类:<i class="icon-map-pin"></i>@Html.ActionLink(Model.Category.Name, "Category", "Home", new { id = Model.CategoryId }, new { @class = "label label-" + colors[new Random().StrictNext() % colors.Length] })
-                                    @if (Model.Seminar.Any())
-                                    {
-                                        <span> | 原所属专题:</span>
-                                        var seminars = Model.Seminar;
-                                        foreach (var s in seminars)
+                                        修改于<span class="text-success">@Model.ModifyDate.ToString("yyyy-MM-dd HH:mm:ss")</span> |
+                                        原分类:<i class="icon-map-pin"></i>@Html.ActionLink(Model.Category.Name, "Category", "Home", new { id = Model.CategoryId }, new { @class = "label label-" + colors[new Random().StrictNext() % colors.Length] })
+                                        @if (Model.Seminar.Any())
                                         {
-                                            @Html.ActionLink(s.Seminar.Title, "Index", "Seminar", new { id = s.SeminarId }, new { @class = "label label-" + colors[new Random().StrictNext() % colors.Length] })<text> </text>
+                                            <span> | 原所属专题:</span>
+                                            var seminars = Model.Seminar;
+                                            foreach (var s in seminars)
+                                            {
+                                                @Html.ActionLink(s.Seminar.Title, "Index", "Seminar", new { id = s.SeminarId }, new { @class = "label label-" + colors[new Random().StrictNext() % colors.Length] })<text> </text>
+                                            }
                                         }
-                                    }
                                     </div>
                                 </div>
                                 @{
@@ -71,44 +71,48 @@
                         </header>
                         <article class="article" id="article">
                             @Html.Raw(Regex.Replace(Model.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", $"<img data-original=\"$1\" alt='{CommonHelper.SystemSettings["Title"]}' title='{CommonHelper.SystemSettings["Title"]}'/>"))
-                            @if(!string.IsNullOrEmpty(Model.ProtectContent)) {
-                            <div class="row protected">
-                                @if(string.IsNullOrEmpty(Context.Session.GetByRedis<string>("ArticleViewToken"))) {
-                                <p class="text-red text-center size24 margin-bot10">↓↓↓恭喜你发现镇站之宝,请注意,前方高能!非战斗人员请及时撤离,这不是演习!↓↓↓</p>
-                                <div class="col-md-6">
-                                    <span class="text-red">以下内容已经隐藏,请输入验证码后查看</span>
-                                    <span class="text-green">【完全免费,不收一分钱】</span>
-                                    <form action="/" method="post" class="form-inline" id="code-token">
-                                        <div class="input-group">
-                                            @Html.AntiForgeryToken()
-                                            <span class="input-group-addon">验证码:</span>
-                                            <input type="text" name="token" id="token" class="form-control" />
-                                            <span class="input-group-btn">
-                                                <button type="submit" class="btn btn-info">查看文章</button>
-                                            </span>
+                            @if (!string.IsNullOrEmpty(Model.ProtectContent))
+                            {
+                                <div class="row protected">
+                                    @if (string.IsNullOrEmpty(Context.Session.GetByRedis<string>("ArticleViewToken")))
+                                    {
+                                        <p class="text-red text-center size24 margin-bot10">↓↓↓恭喜你发现镇站之宝,请注意,前方高能!非战斗人员请及时撤离,这不是演习!↓↓↓</p>
+                                        <div class="col-md-6">
+                                            <span class="text-red">以下内容已经隐藏,请输入验证码后查看</span>
+                                            <span class="text-green">【完全免费,不收一分钱】</span>
+                                            <form action="/" method="post" class="form-inline" id="code-token">
+                                                <div class="input-group">
+                                                    @Html.AntiForgeryToken()
+                                                    <span class="input-group-addon">验证码:</span>
+                                                    <input type="text" name="token" id="token" class="form-control" />
+                                                    <span class="input-group-btn">
+                                                        <button type="submit" class="btn btn-info">查看文章</button>
+                                                    </span>
+                                                </div>
+                                            </form>
+                                            <p class="text-green">温馨提示:将本页面分享到您的社交平台上,如QQ或微信,并保证3h之内不会删除且获得10个以上的点赞或评论后,通过站长QQ私信获取文章访问密码,<span class="text-red">获取密码后本站所有加密文章将永久开放!</span></p>
                                         </div>
-                                    </form>
-                                    <p class="text-green">温馨提示:将本页面分享到您的社交平台上,如QQ或微信,并保证3h之内不会删除且获得10个以上的点赞或评论后,通过站长QQ私信获取文章访问密码,<span class="text-red">获取密码后本站所有加密文章将永久开放!</span></p>
-                                </div>
-                                <div class="col-md-6">
-                                    <span class="text-green">如果你曾经获取过密码,请输入您的邮箱后查看</span>
-                                    <form action="/" method="post" class="form-inline" id="email-token">
-                                        <div class="input-group">
-                                            @Html.AntiForgeryToken()
-                                            <span class="input-group-addon">邮箱:</span>
-                                            <input type="email" name="Email" id="email3" class="form-control" />
-                                            <span class="input-group-btn">
-                                                <button type="submit" class="btn btn-info">查看文章</button>
-                                            </span>
+                                        <div class="col-md-6">
+                                            <span class="text-green">如果你曾经获取过密码,请输入您的邮箱后查看</span>
+                                            <form action="/" method="post" class="form-inline" id="email-token">
+                                                <div class="input-group">
+                                                    @Html.AntiForgeryToken()
+                                                    <span class="input-group-addon">邮箱:</span>
+                                                    <input type="email" name="Email" id="email3" class="form-control" />
+                                                    <span class="input-group-btn">
+                                                        <button type="submit" class="btn btn-info">查看文章</button>
+                                                    </span>
+                                                </div>
+                                            </form>
+                                            <p class="text-green">温馨提示:请确保您的邮箱已经通过站长的登记,如果您未使用邮箱登记,请先联系站长获取文章密码并登记邮箱即可!</p>
                                         </div>
-                                    </form>
-                                    <p class="text-green">温馨提示:请确保您的邮箱已经通过站长的登记,如果您未使用邮箱登记,请先联系站长获取文章密码并登记邮箱即可!</p>
+                                    }
+                                    else
+                                    {
+                                        <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
+                                        @Html.Raw(Regex.Replace(Model.ProtectContent, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", $"<img data-original=\"$1\" alt='{CommonHelper.SystemSettings["Title"]}' title='{CommonHelper.SystemSettings["Title"]}'/>"))
+                                    }
                                 </div>
-                                } else {
-                                <p class="text-red text-center size20">↓↓↓以下是文章加密部分↓↓↓</p>
-                                @Html.Raw(Regex.Replace(Model.ProtectContent, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", $"<img data-original=\"$1\" alt='{CommonHelper.SystemSettings["Title"]}' title='{CommonHelper.SystemSettings["Title"]}'/>"))
-                                }
-                            </div>
                             }
                         </article>
                         <div id="cyReward" role="cylabs" data-use="reward"></div>
@@ -136,7 +140,7 @@
                             PostHistoryVersion next = ViewBag.Next;
                             if (next != null)
                             {
-                                @Html.ActionLink(next.Title, "HistoryVersion", "Post", new { id=next.PostId,hid = next.Id }, null)
+                                @Html.ActionLink(next.Title, "HistoryVersion", "Post", new { id = next.PostId, hid = next.Id }, null)
                             }
                             else
                             {
@@ -148,44 +152,44 @@
                 <!--PC和WAP自适应版-->
                 <div id="SOHUCS" sid="[email protected]"></div>
                 <script type="text/javascript">
-	                (function() {
-		                var appid = 'cytsT3QgK';
-		                var conf = 'prod_0358240040a6c9611add9de991099d42';
-		                var width = window.innerWidth || document.documentElement.clientWidth;
-		                if (width < 960) {
-			                window.document.write(
-				                '<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' +
-				                appid + '&conf=' + conf + '"><\/script>');
-		                } else {
-			                var loadJs = function(d, a) {
-				                var c = document.getElementsByTagName("head")[0] || document.head || document.documentElement;
-				                var b = document.createElement("script");
-				                b.setAttribute("type", "text/javascript");
-				                b.setAttribute("charset", "UTF-8");
-				                b.setAttribute("src", d);
-				                if (typeof a === "function") {
-					                if (window.attachEvent) {
-						                b.onreadystatechange = function() {
-							                var e = b.readyState;
-							                if (e === "loaded" || e === "complete") {
-								                b.onreadystatechange = null;
-								                a()
-							                }
-						                }
-					                } else {
-						                b.onload = a
-					                }
-				                }
-				                c.appendChild(b)
-			                };
-			                loadJs("https://changyan.sohu.com/upload/changyan.js", function() {
-				                window.changyan.api.config({
-					                appid: appid,
-					                conf: conf
-				                })
-			                });
-		                }
-	                })();
+                    (function () {
+                        var appid = 'cytsT3QgK';
+                        var conf = 'prod_0358240040a6c9611add9de991099d42';
+                        var width = window.innerWidth || document.documentElement.clientWidth;
+                        if (width < 960) {
+                            window.document.write(
+                                '<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' +
+                                appid + '&conf=' + conf + '"><\/script>');
+                        } else {
+                            var loadJs = function (d, a) {
+                                var c = document.getElementsByTagName("head")[0] || document.head || document.documentElement;
+                                var b = document.createElement("script");
+                                b.setAttribute("type", "text/javascript");
+                                b.setAttribute("charset", "UTF-8");
+                                b.setAttribute("src", d);
+                                if (typeof a === "function") {
+                                    if (window.attachEvent) {
+                                        b.onreadystatechange = function () {
+                                            var e = b.readyState;
+                                            if (e === "loaded" || e === "complete") {
+                                                b.onreadystatechange = null;
+                                                a()
+                                            }
+                                        }
+                                    } else {
+                                        b.onload = a
+                                    }
+                                }
+                                c.appendChild(b)
+                            };
+                            loadJs("https://changyan.sohu.com/upload/changyan.js", function () {
+                                window.changyan.api.config({
+                                    appid: appid,
+                                    conf: conf
+                                })
+                            });
+                        }
+                    })();
                 </script>
             </div>
         </div>
@@ -195,44 +199,44 @@
 <script src="~/Assets/UEditor/third-party/SyntaxHighlighter/scripts/bundle.min.js"></script>
 <script src="~/Assets/jquery.tocify/jquery.tocify.js"></script>
 <script>
-    $(function() {
-		$("#toc").show();
+    $(function () {
+        $("#toc").show();
         var toc = $("#toc").tocify({
             selectors: ".ibox-content h3,.ibox-content h4,.ibox-content h5"
         }).data("toc-tocify");
-	    $(".tocify>.close").on("click", function(e) {
-		    $(this).parent().hide();
-	    });		
-	    SyntaxHighlighter.all();
-	    SyntaxHighlighter.defaults['toolbar'] = false;
-	    $("#code-token").on("submit", function(e) {
-		    e.preventDefault();
-		    $.post("/post/CheckViewToken", $(this).serialize(), function(data) {
-			    if (data.Success) {
-				    window.location.reload();
-			    } else {
-				    window.notie.alert({
-					    type: 3,
-					    text: data.Message,
-					    time: 4
-				    });
-			    }
-		    });
-	    });
-	    $("#email-token").on("submit", function(e) {
-		    e.preventDefault();
-		    $.post("/post/getviewtoken", $(this).serialize(), function(data) {
-			    if (data.Success) {
-				    window.localStorage.setItem("email",$("#email3").val());
-				    window.location.reload();
-			    } else {
-				    window.notie.alert({
-					    type: 3,
-					    text: data.Message,
-					    time: 4
-				    });
-			    }
-		    });
-	    });
-	})
+        $(".tocify>.close").on("click", function (e) {
+            $(this).parent().hide();
+        });
+        SyntaxHighlighter.all();
+        SyntaxHighlighter.defaults['toolbar'] = false;
+        $("#code-token").on("submit", function (e) {
+            e.preventDefault();
+            $.post("/post/CheckViewToken", $(this).serialize(), function (data) {
+                if (data.Success) {
+                    window.location.reload();
+                } else {
+                    window.notie.alert({
+                        type: 3,
+                        text: data.Message,
+                        time: 4
+                    });
+                }
+            });
+        });
+        $("#email-token").on("submit", function (e) {
+            e.preventDefault();
+            $.post("/post/getviewtoken", $(this).serialize(), function (data) {
+                if (data.Success) {
+                    window.localStorage.setItem("email", $("#email3").val());
+                    window.location.reload();
+                } else {
+                    window.notie.alert({
+                        type: 3,
+                        text: data.Message,
+                        time: 4
+                    });
+                }
+            });
+        });
+    })
 </script>

+ 6 - 6
src/Masuit.MyBlogs.Core/Views/Post/Publish_Admin.cshtml

@@ -2,28 +2,28 @@
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.Entity
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Win32
 @{
     ViewBag.Title = "投稿";
     Layout = "~/Views/Shared/_Layout.cshtml";
     string[] colors = { "success", "info", "warning", "danger", "default" };
     UserInfoOutputDto user = Context.Session.GetByRedis<UserInfoOutputDto>(SessionKey.UserInfo);
-    List<Category> cats= ViewBag.Category;
+    List<Category> cats = ViewBag.Category;
 }
 <link href="~/Assets/fileupload/filestyle.css" rel="stylesheet" />
 <link href="~/Assets/semantic/semantic.css" rel="stylesheet" />
 <div class="container">
     <ol class="cd-breadcrumb triangle">
-        <li>@Html.ActionLink("首页","Index","Home")</li>
+        <li>@Html.ActionLink("首页", "Index", "Home")</li>
         <li class="current"><em>@ViewBag.Title</em></li>
     </ol>
-    <hr/>
+    <hr />
     <form class="form-group" id="article-form" method="post" onsubmit="return false">
         @*文章表单*@
         @Html.AntiForgeryToken()
-        <input type="hidden" name="IsWordDocument" id="IsWordDocument" value="false"/>
-        <input type="hidden" name="ResourceName" id="ResourceName"/>
+        <input type="hidden" name="IsWordDocument" id="IsWordDocument" value="false" />
+        <input type="hidden" name="ResourceName" id="ResourceName" />
         <input type="hidden" class="form-control" id="Author" name="Author" value="@user.NickName">
         <input type="hidden" class="form-control" id="Email" name="Email" value="@user.Email">
         <div class="input-group">

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Seminar/Index.cshtml

@@ -1,7 +1,7 @@
 @using AngleSharp.Network.Default
 @using Masuit.MyBlogs.Core.Models.DTO
 @using Masuit.MyBlogs.Core.Models.ViewModel
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @model IList<Masuit.MyBlogs.Core.Models.DTO.PostOutputDto>
 @{
     Layout = "~/Views/Shared/_Layout.cshtml";

+ 1 - 1
src/Masuit.MyBlogs.Core/Views/Shared/_Layout.cshtml

@@ -3,7 +3,7 @@
 @using Masuit.MyBlogs.Core.Models.Enum
 @using Masuit.MyBlogs.Core.Models.ViewModel
 @using Masuit.Tools
-@using Masuit.Tools.Core.Net
+@using Masuit.MyBlogs.Core.Extensions
 @using Masuit.Tools.Win32
 @{
     string[] colors = { "success", "info", "warning", "danger", "default" };