YbRapidSolution.MVC项目首页缓存没有起作用
Response.Cache.SetOmitVaryStar(true);
文件方面的内容,增加了这个语句
没有的话缓存没起作用,增加这个语句可提高系统性能。
HomeController:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Glimpse.Mvc.Message;
using Yb.Data.Provider;
using YbRapidSolution.Cms.Drawing;
using YbRapidSolution.Core.IO;
using YbRapidSolution.Entities;
using YbRapidSolution.Mvc.Models;
using YbRapidSolution.Presenter;
using YbRapidSolution.Presenter.Controllers;
using YbRapidSolution.Services;
using YbRapidSolution.Services.Cms; namespace YbRapidSolution.Mvc.Controllers.Security
{
[AllowAnonymous]
public class HomeController : Controller
{
#region 字段 private readonly ICmsColumnService _colService;
private readonly ICmsSettingService _settingService;
private readonly ICmsPostService _postService;
private readonly ICmsPollService _pollService;
private readonly ICmsContentService _contentService;
private readonly ICmsCommentService _commentService;
private readonly IMediaProvider _mediaProvider;
private readonly IMediaCacheProvider _mediaCacheProvider; #endregion #region 构造器 public HomeController(ICmsColumnService colService,
ICmsContentService contentService,
ICmsCommentService commentService,
IMediaProvider mediaProvider,
IMediaCacheProvider mediaCacheProvider,
ICmsSettingService settingService,
ICmsPostService postService,
ICmsPollService pollService)
{
_colService = colService;
_settingService = settingService;
_contentService = contentService;
_commentService = commentService;
_mediaProvider = mediaProvider;
_mediaCacheProvider = mediaCacheProvider;
_postService = postService;
_pollService = pollService;
} #endregion #region 私有方法 private void SetService()
{
ViewBag.CmsSettingService = _settingService;
ViewBag.CmsColumnService = _colService;
ViewBag.CmsContentService = _contentService;
ViewBag.CmsPostService = _postService;
ViewBag.CmsPollService = _pollService;
ViewBag.CmsCommentService = _commentService;
} #endregion #region 首页方法 // GET: /Logon/
[AllowAnonymous]
public ActionResult Index()
{
var setting =_settingService.Load();
var home = _colService.GetHomeColumn()
?? new CmsColumn(); var model = setting.GetPageModel(home);
if (this.TempData.ContainsKey("HideLogin"))
{
model.HideLogin = (bool)this.TempData["HideLogin"];
}
else
{
model.HideLogin=false;
}
model.NavColumnId = model.ID;
model.CurColumnId = model.ID;
SetService();
return View(model);
} [AllowAnonymous]
public ActionResult Dashboard()
{
this.TempData["HideLogin"] = true;
return RedirectToAction("Index");
} #endregion #region 页面方法 [AllowAnonymous]
public ActionResult ColumnPage(string columnId,string navToId,int pageIndex=)
{
var column = _colService.GetById(columnId);
if (column == null)
return RedirectToAction("Index");
if (column.IsRedirect && !string.IsNullOrWhiteSpace(column.RedirectUrl))
{
return Redirect(column.RedirectUrl);
}
var path = "";
switch (column.TemplateType)
{
case :
path = column.CoverTemplatePath;
break;
case :
path = column.ListTemplatePath;
break;
case :
path = column.ContentTemplatePath;
break;
case :
path = column.SearchTemplatePath;
break;
}
if (string.IsNullOrWhiteSpace(path))
{
return RedirectToAction("Index");
}
var setting = _settingService.Load();
var model = setting.GetPageModel(column);
model.CurColumnId = columnId;
model.NavColumnId = navToId;
model.PageIndex = pageIndex;
SetService();
return View(path, model);
}
/// <summary>
/// 内容页
/// </summary>
/// <param name="columnId"></param>
/// <param name="navToId"></param>
/// <returns></returns>
[AllowAnonymous]
public ActionResult ContentPage(string id,string columnId, string navToId)
{
var column = _colService.GetById(columnId);
if (column == null)
return RedirectToAction("Index");
if (column.IsRedirect && !string.IsNullOrWhiteSpace(column.RedirectUrl))
{
return Redirect(column.RedirectUrl);
}
var path = "";
switch (column.TemplateType)
{
case :
path = column.CoverTemplatePath;
break;
case :
path = column.ContentTemplatePath;
break;
}
if (string.IsNullOrWhiteSpace(path))
{
return RedirectToAction("Index");
}
var setting = _settingService.Load();
var model = setting.GetPageModel(column);
model.CurColumnId = columnId;
model.NavColumnId = navToId;
model.CurContentId = id;
SetService();
return View(path, model);
} #endregion #region 评论操作 /// <summary>
/// 添加评论
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[ValidateInput(false)]
public JsonResult AddComment(CmsComment comment)
{
var result = new EasyUIMessage();
ViewBag.CmsCommentService = _commentService;
comment.ID = Guid.NewGuid().ToIdString();
comment.CreatedDate = DateTime.Now;
comment.CreatedFName = User.Identity.Name; var validResult = _commentService.Validate(comment);
if (!validResult.IsValid)
{
result.success = false;
result.msg = validResult.Errors[].ErrorMessage;
return Json(result);
}
var userReplyAudit = _settingService.Load().UserReplyAudit;
comment.Cmd = userReplyAudit ? Cmd.Save : Cmd.Publish;
try
{
_commentService.Insert(comment);
comment.Body = ""; result.msg = userReplyAudit ? "评论提交成功,需管理员审核通过后才能显示" : "评论提交成功";
result.success = true;
}
catch (Exception ex)
{
result.success = false;
result.msg = ex.Message;
}
return Json(result);
}
/// <summary>
/// 添加评论
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public PartialViewResult CommentList(string parentId, int pageSize = , int pageIndex = , string targetId=null)
{
ViewBag.PageIndex = pageIndex;
ViewBag.CmsCommentService = _commentService;
var items = _commentService.FindBy(c => c.ParentId == parentId, false,
pageIndex, pageSize, c => c.OrderByDescending(d => d.CreatedDate));
var model = new CmsPagerDataModel()
{
Data = items,
ActionName=this.RouteData.Values["action"].ToString(),
ControllerName= this.RouteData.Values["controller"].ToString(),
RouteValues = new { parentId, targetId },
TargetId=targetId
};
SetService();
return PartialView("_CommentList", model);
} #endregion #region 文件操作 [AllowAnonymous]
[OutputCache(Duration = )]
public FileResult GetImg(string id)
{
return GetFile(id);
}
/// <summary>
/// Gets the thumbnail for the embedded resource with the given id. The thumbnail
/// resources are specified in Piranha.Drawing.Thumbnails.
/// </summary>
/// <param name="id">Content id</param>
/// <param name="size">The desired size</param>
//[YbMvcAuthorize()]
[AllowAnonymous]
[OutputCache(Duration = , VaryByParam = "*")]
public FileResult GetThumbnailBySize(string id, bool draft,int randNum=, int size = )
{
return GetThumbnailBy(id,draft,randNum,size,size);
}
/// <summary>
/// Gets the thumbnail for the embedded resource with the given id. The thumbnail
/// resources are specified in Piranha.Drawing.Thumbnails.
/// </summary>
/// <param name="id">Content id</param>
/// <param name="size">The desired size</param>
[AllowAnonymous]
[OutputCache(Duration = ,VaryByParam="size")]
public FileResult GetImgBySize(string id, int size = )
{
return GetThumbnailBySize(id, false, , size);
} [AllowAnonymous]
[OutputCache(Duration = , VaryByParam = "*")]
public FileResult GetThumbnailBy(string id, bool draft, int randNum = , int width = , int height = )
{
Response.Cache.SetOmitVaryStar(true);
//首先从缓存中获取
var data = draft
? _mediaCacheProvider.GetDraft(id, width, height)
: _mediaCacheProvider.Get(id, width, height); if (data == null)
{
//获取内容
var content = _contentService.GetById(id, draft);
if (content != null)
{
Stream strm;
if (content.IsFolder)
{
//为文件夹,加载文件夹图标
var resource = Math.Min(width,height) <=
? Thumbnails.GetByType("folder-small")
: Thumbnails.GetByType("folder");
strm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
}
else if (content.ContentKind != ContentKind.Image)
{
//不为图片,根据类型加载资源图片
var type = Thumbnails.ContainsKeyByType(content.ContentType)
? content.ContentType : "default";
var resource = Thumbnails.GetByType(type);
strm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
}
else
{
//为图片,根据大下生成缩略图
var imgData = draft
? _mediaProvider.GetDraft(id)
: _mediaProvider.Get(id); if (imgData == null)
{
//不存在,使用默认图片
var resource = Thumbnails.GetByType("default");
strm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
}
else
{
strm = new MemoryStream(imgData);
}
}
var img = Image.FromStream(strm);
img = ImageUtils.Resize(img, width, height);
using (var mem = new MemoryStream())
{
img.Save(mem, ImageFormat.Png);
data = mem.ToArray();
}
strm.Close(); if (draft)
_mediaCacheProvider.PutDraft(id, data, width, height);
else
_mediaCacheProvider.Put(id, data, width, height);
}
}
return File(data, "image/png");
} /// <summary>
/// Gets the thumbnail for the embedded resource with the given id. The thumbnail
/// resources are specified in Piranha.Drawing.Thumbnails.
/// </summary>
/// <param name="id">Content id</param>
/// <param name="size">The desired size</param>
[AllowAnonymous]
[OutputCache(Duration = , VaryByParam = "size")]
public FileResult GetImgBy(string id, int width = , int height = )
{
return GetThumbnailBy(id, false, , width, height);
} [AllowAnonymous]
public FileResult GetFile(string id)
{
Response.Cache.SetOmitVaryStar(true);
var content = _contentService.GetById(id);
if (content == null || content.IsFolder)
return null;
var data=_mediaProvider.Get(id);
if (data == null)
return null;
return File(data, content.ContentType, content.FileName);
} [AllowAnonymous]
public FileResult GetFileByPath(string fname)
{
Response.Cache.SetOmitVaryStar(true);
var content = _contentService.GetByFName(fname);
if (content == null || content.IsFolder)
return null;
var data = _mediaProvider.Get(content.ID);
if (data == null)
return null;
return File(data, content.ContentType, content.FileName);
} #endregion #region 图片轮播 [AllowAnonymous]
public PartialViewResult CarouseSide(string fname)
{
ViewBag.CmsContentService = _contentService;
SetService();
return PartialView("_CarouseSide", fname);
} #endregion #region 问卷调查方法 /// <summary>
/// 提交问卷调查
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public PartialViewResult SubmitPoll()
{
if (!this.Request.Form.AllKeys.Contains("PollId"))
return PartialView("_MsgDialog","提交失败:当前问卷调查不存在");
var pollId = this.Request.Form.Get("PollId");
if (string.IsNullOrWhiteSpace(pollId))
{
return PartialView("_MsgDialog", "提交失败:当前问卷调查不存在");
}
var poll = _pollService.GetById(pollId.Trim());
if (poll==null)
{
return PartialView("_MsgDialog", "提交失败:当前问卷调查已被删除");
}
var date = DateTime.Now;
if (!poll.PollPublished
|| (poll.StartDate.HasValue && poll.StartDate.Value > date)
|| (poll.EndDate.HasValue && poll.EndDate.Value < date))
{
return PartialView("_MsgDialog", "提交失败:当前问卷调查已关闭");
}
string ip="", cookie="", userName="";
if(poll.LimitIP)
ip = AccountController.GetIP4Address();
if (poll.LimitCookie)
{
if (Request.Cookies.AllKeys.Contains(poll.ID))
{
return PartialView("_MsgDialog", "提交失败:该问卷调查已提交,不允许重复提交");
}
cookie = poll.ID;
} if (poll.LimitGuest)
{
if(!User.Identity.IsAuthenticated)
return PartialView("_MsgDialog", "提交失败:该问卷调查需登录后才能提交");
userName = User.Identity.Name;
}
if (_pollService.Exists(ip, cookie, userName))
{
return PartialView("_MsgDialog", "提交失败:该问卷调查已提交,不允许重复提交");
} var pollVoting = new CmsPollVoting
{
ID = Guid.NewGuid().ToIdString(),
PollId = poll.ID,
IP = ip,
UserName = userName,
Cookie = cookie,
CmsPollVotingItem = new List<CmsPollVotingItem>(poll.CmsPollItem.Count)
}; foreach (var item in poll.CmsPollItem)
{
if (!this.Request.Form.AllKeys.Contains(item.ID))
{
return PartialView("_MsgDialog", string.Format("提交失败:‘{0}’未选择。", item.Name));
}
var str = this.Request.Form.Get(item.ID);
if (string.IsNullOrWhiteSpace(str))
{
return PartialView("_MsgDialog", string.Format("提交失败:‘{0}’可选型未选择。", item.Name));
} var votingItem = new CmsPollVotingItem
{
ID = Guid.NewGuid().ToIdString(),
PollItemId = item.ID,
PollVotingId = pollVoting.ID
};
pollVoting.CmsPollVotingItem.Add(votingItem); votingItem.CmsPollVotingAnswer = new List<CmsPollVotingAnswer>(item.CmsPollAnswer.Count);
//获取投票值
var selectValues = str.Trim().Split(',').Distinct();
//获取所有可选项
var allAnswerIds = item.CmsPollAnswer.Select(c => c.ID).ToList();
var dic=item.CmsPollAnswer.ToDictionary(c => c.ID);
foreach (var value in selectValues)
{
if (!dic.ContainsKey(value))
{
return PartialView("_MsgDialog", string.Format("提交失败:‘{0}’可选型未选择不存在。", item.Name));
} var votingAnswer = new CmsPollVotingAnswer()
{
ID = Guid.NewGuid().ToIdString(),
PollAnswerId = value,
PollVotingItemId = item.ID,
Value = dic[value].Value
};
votingItem.CmsPollVotingAnswer.Add(votingAnswer);
}
}
try
{
_pollService.Insert(pollVoting);
if (cookie != "")
{
HttpCookie curCookie = new HttpCookie(cookie)
{
Expires = DateTime.Now.AddYears()
};
System.Web.HttpContext.Current.Response.Cookies.Add(curCookie);
}
return PartialView("_MsgDialog", "问卷调查提交成功,谢谢您的参与");
}
catch(Exception er)
{
AuditLogApi.Error(er.Message, er);
return PartialView("_MsgDialog", "提交失败:系统出现异常,请查看审计日志了解详细信息");
}
}
[AllowAnonymous]
public PartialViewResult ViewPollResult(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
return PartialView("_MsgDialog", "当前问卷调查不存在");
}
var poll = _pollService.GetById(id.Trim());
if (poll == null)
{
return PartialView("_MsgDialog", "当前问卷调查不存在");
}
if (!poll.ResultPublished)
{
return PartialView("_MsgDialog", "当前问卷调查暂未发布");
}
var total = poll.CmsPollVoting.Count;
foreach (var item in poll.CmsPollItem)
{
foreach (var answer in item.CmsPollAnswer)
{
answer.Count = item.CmsPollVotingItem
.SelectMany(c => c.CmsPollVotingAnswer)
.Count(c => c.PollAnswerId == answer.ID);
answer.Ratio = total == ? 0m : answer.Count / (decimal)total;
}
}
return PartialView("_PollResult", poll);
}
#endregion }
}
YbRapidSolution.MVC项目首页缓存没有起作用的更多相关文章
- YbRapidSolution.MVC项目首页分页没有起作用
@model YbRapidSolution.Mvc.Models.CmsPagerDataModel <nav> <ul class="pager"> & ...
- spring MVC项目中,欢迎页首页根路径到底是怎么设置的
0. 问题: 如何改mvc中项目的欢迎页,或者叫做根路径 一个东西快弄完了,就剩下一个问题,应该是个小问题.就是mvc项目的欢迎页,怎么给改下呢. 这个项目是通过mvn建立的,整个项目的原型就是spr ...
- 谈谈MVC项目中的缓存功能设计的相关问题
本文收集一些关于项目中为什么需要使用缓存功能,以及怎么使用等,在实际开发中对缓存的设计的考虑 为什么需要讨论缓存呢? 缓存是一个中大型系统所必须考虑的问题.为了避免每次请求都去访问后台的资源(例如数据 ...
- 习题-任务2初始ASP.NET MVC项目开发
一.选择题 1.在ASP.NET MVC项目的RouteConfig.cs文件中,( )方法注册了默认的路由配置. A.RegisterMap B.RegisterRoutes C. ...
- Spring MVC 程序首页的设置 - 一号门-程序员的工作,程序员的生活(java,python,delphi实战)
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- Java Spring MVC项目搭建(二)——项目配置
1.站点配置文件web.xml 每一个Spring MVC 项目都必须有一个站点配置文件web.xml,他的主要功能吗....有一位大哥已经整理的很好,我借来了,大家看看: 引用博客地址: http: ...
- 简单Spring MVC项目搭建
1.新建Project 开发环境我使用的是IDEA,其实使用什么都是大同小异的,关键是自己用的顺手. 首先,左上角File→New→Project.在Project页面选择Maven,然后勾上图中所示 ...
- 使用gulp解决RequireJS项目前端缓存问题(一)
1.前言 前端缓存一直是个令人头疼的问题,你有可能见过下面博客园首页的资源文件链接: 有没有发现文件名后面有一串不规则的东东,没错,这就是运用缓存机制,我们今天研究的就是这种东西. 先堵为快,猛戳链接 ...
- 本地MVC项目发布到IIS服务器
0瞎扯 朋友们有时候我们写个一个web程序只能使用卡西尼服务器调试,下面我教大家发布到IIS服务器上(包括本地ISS7.5和远程服务器 IIS) 1.VS发布 a.点击web项目->发布
随机推荐
- ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click 'Restart'
ADB not responding. If you'd like to retry, then please manually kill "adb.exe" and click ...
- Solr搜索基础
本例我们使用类库和代码均来自: http://www.cnblogs.com/TerryLiang/archive/2011/04/17/2018962.html 使用C#来模拟搜索.索引建立.删除. ...
- Function---hdu5875(大连网选,区间连续求余)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5875 题意:有n个数,m个查询,每个查询有一个区间[L, R], 求ans, ans = ...
- documentElement和ownerDocument和ownerElement
1.document.documentElement是指文档根节点----HTML元素 2.element.ownerDocument是指当前元素所在的文档对象----document 3.attrO ...
- Selenium2学习-036-WebUI自动化实战实例-034-JavaScript 在 Selenium 自动化中的应用实例之六(获取 JS 执行结果返回值)
Selenium 获取 JavaScript 返回值非常简单,只需要在 js 脚本中将需要返回的数据 return 就可以,然后通过方法返回 js 的执行结果,方法源码如下所示: /** * Get ...
- CentOS6.5Minimal安装Gitlab7.5
文章出处:http://www.restran.net/2015/04/09/gilab-centos-installation-note/ 在 CentOS 6.5 Minimal 系统环境下,用源 ...
- EF Code First教程-02.1 Fluent API约定配置
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- T4教程1 T4模版引擎之基础入门
T4模版引擎之基础入门 额,T4好陌生的名字,和NuGet一样很悲催,不为世人所熟知,却又在背后默默无闻的奉献着,直到现在我们项目组的人除了我之外,其它人还是对其豪无兴趣,基本上是连看一眼都懒得看 ...
- Mysql 5.7.7
1.安装Mysql(需要管理员权限) 2.启动Mysql 3.连接Mysql Mysql刚安装成功后可输入 mysql -u root -p ,然后回车,提示输入密码,由于是第一次连接,不用输入密码也 ...
- Hive -- 基于Hadoop的数据仓库分析工具
Hive是一个基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,通过类SQL语句快速实现简单的MapReduce统计,不必开发专门的MapReduce应用,十分适合数据仓库 ...