VirtualPathProvider的使用
解决的问题,加载数据库中的UI
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
DbPathProvider provider = new DbPathProvider();
HostingEnvironment.RegisterVirtualPathProvider(provider);
}
}
public class DbPathProvider : VirtualPathProvider
{
protected bo_view cbo_view = null;
Dictionary<string, FakeCacheDependency> dicFakeCacheDependencys = new Dictionary<string, FakeCacheDependency>();
public DbPathProvider() : base()
{
}
public override string GetCacheKey(string virtualPath)
{
string mvirtualPath = getmvirtual(virtualPath);
ICriteria<bo_view> wbo_view = CriteriaFactory.Create<bo_view>();
wbo_view = wbo_view.Where(q => q.pagename == mvirtualPath);
cbo_view = bo_view.Fetch(wbo_view);
if (!cbo_view.IsNew)
{
FakeCacheDependency fdc = null;
if (dicFakeCacheDependencys.TryGetValue(cbo_view.pagename, out fdc))
{
fdc.Clear(cbo_view.operdate);
}
}
return base.GetCacheKey(virtualPath);
}
public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{
if (cbo_view.IsNew)
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
dicFakeCacheDependencys[cbo_view.pagename] = new FakeCacheDependency(cbo_view.operdate);
return dicFakeCacheDependencys[cbo_view.pagename];
}
public class FakeCacheDependency : System.Web.Caching.CacheDependency
{
public FakeCacheDependency(DateTime lastModified)
{
base.SetUtcLastModified(lastModified);
}
public FakeCacheDependency()
{
base.SetUtcLastModified(DateTime.UtcNow);
}
public void Clear(DateTime lastModified)
{
if (this.UtcLastModified != lastModified)
{
base.SetUtcLastModified(lastModified);
NotifyDependencyChanged(this, EventArgs.Empty);
}
}
}
public override bool DirectoryExists(string virtualDir)
{
if (cbo_view.IsNew)
base.DirectoryExists(virtualDir);
return true;
}
public override bool FileExists(string virtualPath)
{
if (cbo_view.IsNew)
base.FileExists(virtualPath);
return true;
}
public override VirtualFile GetFile(string virtualPath)
{
if (cbo_view.IsNew)
{
return this.Previous.GetFile(virtualPath);
}
return new DbVirtualFile(virtualPath, cbo_view);
}
private static string getmvirtual(string virtualPath)
{
string mvirtualPath = virtualPath;
int fileindex = virtualPath.LastIndexOf('/');
if (fileindex >= 0)
{
mvirtualPath = virtualPath.Substring(fileindex);
}
return mvirtualPath;
}
}
public class DBCacheDependency : CacheDependency
{
public DBCacheDependency(string path) : base(HttpRuntime.AppDomainAppPath.TrimEnd('\\') + "\\web.config")
{
FinishInit();
}
public new bool HasChanged
{
get { return true; }
}
static string GetDependKey()
{
return System.Guid.NewGuid().ToString();
}
}
public class DbVirtualFile : VirtualFile
{
private static string getmvirtual(string virtualPath)
{
string mvirtualPath = virtualPath;
int fileindex = virtualPath.LastIndexOf('/');
if (fileindex >= 0)
{
mvirtualPath = virtualPath.Substring(fileindex);
}
return mvirtualPath;
}
protected bo_view cbo_view = null;
public DbVirtualFile(string filename, bo_view mbo_view) : base(filename)
{
cbo_view = mbo_view;
}
public override Stream Open()
{
if (cbo_view.IsNew)
{
throw new Exception("此资源不存在");
}
byte[] bytes = System.Text.Encoding.Default.GetBytes(cbo_view.viewcontent);
return new System.IO.MemoryStream(bytes);
}
}
关键点:
在创建ui的时候,要注意@ page指令的写法
<%@ Page Title="" Language="C#" MasterPageFile="~/admin/Admin.Master" AutoEventWireup="true" CodeBehind="mm.aspx.cs" Inherits="MyBasePage" CompilationMode="Always" %> CodeBedhid可以是不存在的,YHWebCore.Business.MyBasePage如果没有后台代码,可以使用基页面。
VirtualPathProvider的使用的更多相关文章
- 9.2.2 .net framework下的MVC 控件的封装(下)
控件封装的部分说明 可能有人觉得应该前后端分离,我也承认这是应该的方向,我们也在考虑使用ng2等简化前端.但是,我们封装控件还是因为如下原因综合考虑的: 我们这是个框架,上面支撑了许多个应用,包含几百 ...
- 《Pro ASP.NET MVC 4》异常整理
最近在和同学一起研究毕业设计,准备模仿<Pro ASP.NET MVC 4>里面的SportsStore设计模式和测试驱动开发. 由于和书中VS版本不同,发现不少问题,在此总结. 用户代码 ...
- ASP.NET MVC 4 视图页去哪里儿
这里特别感谢 swagon 提到了Displaymodeprovider,所以才有了本篇博客,也使我对[View的呈现]中寻找视图页的过程有了清晰的认识! 前戏 在MVC中,执行完Action之后,会 ...
- Mvc 模块化开发
在Mvc中,标准的模块化开发方式是使用Areas,每一个Area都可以注册自己的路由,使用自己的控件器与视图.但是在具体使用上它有如下两个限制 1.必须把视图文件放到主项目的Areas文件夹下才能生效 ...
- [转]ASP.NET MVC Dynamic Themes
本文转自:http://www.codeproject.com/Articles/32847/ASP-NET-MVC-Dynamic-Themes Download source code - 148 ...
- Orchard CMS中如何打包不带源码的模块
在Orchard CMS的官网已经提供了文档说明如何打包,但是如果使用它的打包方式,打好的nuget包是带源代码的.如果是为开源系统写模块,不需要关注源代码是否可见.但是如果是用Orchard CMS ...
- 白话学习MVC(十)View的呈现二
本节将接着<白话学习MVC(九)View的呈现一>来继续对ViewResult的详细执行过程进行分析! 9.ViewResult ViewResult将视图页的内容响应给客户端! 由于Vi ...
- NopCommerce使用Autofac实现依赖注入
NopCommerce的依赖注入是用的AutoFac组件,这个组件在nuget可以获取,而IOC反转控制常见的实现手段之一就是DI依赖注入,而依赖注入的方式通常有:接口注入.Setter注入和构造函数 ...
- ASP.NET获取路径的方法
原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath; // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\p ...
随机推荐
- zepto之tap事件点透问题分析及解决方案
点透现象出现的场景: 当A/B两个层上下z轴重叠,上层的A点击后消失或移开(这一点很重要),并且B元素本身有默认click事件(如a标签)或绑定了click事件.在这种情况下,点击A/B重叠的部分,就 ...
- 超详细Web前端开发规范文档
http://www.w3cfuns.com/notes/26488/c2ae788c77f835357025026a148b9863.html
- Java的Json解析包FastJson使用
阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser. ...
- QL Server 2008 所有账号丢失sysadmin权限,sa账号亦没有开启,该如何解决??
1. 用Run as a administrator打开命令提示符里输入NET STOP MSSQLSERVER, 即停止MSSQLSERVER运行. 2. 在命令提示符里输入 NET START M ...
- 344. Reverse String
https://leetcode.com/problems/reverse-string/ Python语法糖爆炸时间 class Solution(object): def reverseStrin ...
- oracleDBA-D1
一.数据库备份 1.测试系统环境:win10 64位 企业版 测试数据库环境:oracle11gR2 2.步骤: I.首先以sysdba权限用户登录数据库,命令: SQL> connect 超 ...
- Yii 1开发日记 -- 搜索功能及Checkbox的实现
用yii 1实现后台的搜索功能,效果如下图: 1.模型中: public function search() { $criteria = new CDbCriteria; //独立高级搜索 if(is ...
- MySql触发器语法总结
经过昨天多次失败,今天终于将我要实现的触发器功能写成功了,触发器代码如下: -- use dbfortest; drop trigger if exists tg_before_insert_on_d ...
- python笔记7:日期和时间
Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为单位的浮点小数. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长时间来表示. 时间 ...
- iOS 字符串删除 DOM
iOS string 删除 包含的 DOM NSMutableString *mutableString = [NSMutableString stringWithString:responseSt ...