国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

MVC靜態化頁面

2024-04-27 15:10:05
字體:
來源:轉載
供稿:網友

MVC靜態化頁面

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace WF_HightFood.App_Start { public class StaticFilterAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { //filterContext.HttpContext.Response.Write("OnActionExecuted</br>"); base.OnActionExecuted(filterContext); } public override void OnActionExecuting(ActionExecutingContext filterContext) { // filterContext.HttpContext.Response.Write("OnActionExecuting</br>"); base.OnActionExecuting(filterContext); } public override void OnResultExecuted(ResultExecutedContext filterContext) { //filterContext.HttpContext.Response.Write("OnResultExecuted</br>"); if (filterContext.HttpContext.Response.StatusCode == 200) { filterContext.HttpContext.Response.Filter = new StaticFileWriteResponseFilterWrapper(filterContext.HttpContext.Response.Filter, filterContext); } // filterContext.HttpContext.Response.Charset = "utf8"; base.OnResultExecuted(filterContext); } public override void OnResultExecuting(ResultExecutingContext filterContext) { // filterContext.HttpContext.Response.Write("OnResultExecuting</br>"); base.OnResultExecuting(filterContext); } } class StaticFileWriteResponseFilterWrapper : System.IO.Stream { PRivate Stream inner; private FileStream writer; private ControllerContext context; private int expireSconds; private bool filter; private string tempPath, path; public StaticFileWriteResponseFilterWrapper(System.IO.Stream s, ControllerContext context, int expireSeconds = 600) { this.filter = false; this.inner = s; this.context = context; this.expireSconds = expireSeconds; this.EnsureStaticFile(); } void EnsureStaticFile() { this.path = this.context.HttpContext.Server.MapPath(HttpContext.Current.Request.Path); if (!Path.HasExtension(path)) { return; } if (!".html".Equals(Path.GetExtension(HttpContext.Current.Request.Path))) { return; } if (File.Exists(path)) { var delay = DateTime.UtcNow - File.GetCreationTimeUtc(path); if (delay.TotalSeconds <= this.expireSconds) { return; } File.Delete(path); } else { var dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { try { Directory.CreateDirectory(Path.GetDirectoryName(path)); } catch { } } } this.filter = true; this.tempPath = this.path + "_" + DateTime.Now.Ticks; try { writer = new FileStream(tempPath, FileMode.Create, Fileaccess.Write); } catch { this.filter = false; } } public override bool CanRead { get { return inner.CanRead; } } public override bool CanSeek { get { return inner.CanSeek; } } public override bool CanWrite { get { return inner.CanWrite; } } public override void Flush() { inner.Flush(); } public override long Length { get { return inner.Length; } } public override long Position { get { return inner.Position; } set { inner.Position = value; } } public override int Read(byte[] buffer, int offset, int count) { return inner.Read(buffer, offset, count); } public override long Seek(long offset, System.IO.SeekOrigin origin) { return inner.Seek(offset, origin); } public override void SetLength(long value) { inner.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { try { inner.Write(buffer, offset, count); } catch (Exception ex) { } try { this.writer.Write(buffer, offset, count); } catch (Exception ex) { } } protected override void Dispose(bool disposing) { if (this.filter) { try { if (this.writer != null) { this.writer.Dispose(); this.writer = null; } File.Delete(this.path); File.Move(this.tempPath, this.path); #region 生成文件日志 #endregion } catch { } } base.Dispose(disposing); } } } using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; using EnYuan.SMS; using YJY.Site.SSO; using EnYuan.BSS.User; using EnYuan.BSS.User.Dto; using WF_HightFood.App_Code; namespace WF_HightFood.App_Start { public class SSOFilterAttribute : ActionFilterAttribute { public string Message { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { //if (!filterContext.HttpContext.Request.Url.ToString().ToLower().StartsWith("http://www.")) //{ // filterContext.HttpContext.Response.Redirect(filterContext.HttpContext.Request.Url.ToString().Replace("http://", "http://www.")); // return; //} var sso_cookies = filterContext.HttpContext.Request.Cookies["sso_token"]; if (sso_cookies == null || sso_cookies.Value == null || sso_cookies.Value.Equals("")) { //清空所有cookies filterContext.HttpContext.Request.Cookies.Clear(); //如果不存在token,跳轉到驗證站點進行驗證; filterContext.HttpContext.Response.Redirect("http://jump.yuan.cn/Home/index/?type=mvc&backurl=" + filterContext.HttpContext.Request.Url.ToString()); return; } else { //如過存在token,檢測登錄狀態 var userid = ServiceLocator.Create<ISSOService>().CheckUser(sso_cookies.Value); if (userid != null) { if (filterContext.HttpContext.session["userid"] != userid || filterContext.HttpContext.Session["userid"] == null || filterContext.HttpContext.Session["isV使用方法:

[StaticFilter] public ActionResult Index() {

return View();

}

原文地址:http://blog.csdn.net/lybwwp/article/details/26503765


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通山县| 九寨沟县| 炉霍县| 仁化县| 漾濞| 西林县| 从化市| 昌邑市| 景谷| 信丰县| 武冈市| 河池市| 凤庆县| 繁昌县| 黑龙江省| 含山县| 南皮县| 阿瓦提县| 土默特左旗| 宣武区| 台江县| 大宁县| 旌德县| 遵化市| 徐州市| 威信县| 开鲁县| 图木舒克市| 洛浦县| 崇明县| 灵璧县| 兴隆县| 饶阳县| 朝阳区| 蓝田县| 利川市| 安多县| 门头沟区| 萨迦县| 竹山县| 舟曲县|