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 ...
随机推荐
- select2 demo
https://select2.github.io/examples.html 一大堆的坑: 1. 不同版本之间貌似不兼容,对应版本看对应的文档. 2. 4.0.3版本: 1). 自定义渲染的opti ...
- 收集免费可用稳定的vpn
收集免费可用稳定的vpn,经常用到,所以记录一下,方便自己不备之需. 1,https://www.lvbeivpn.cc/share.shtml?id=a3bd9527225d4746bb3a5761 ...
- Node.js配合node-http-proxy解决本地开发ajax跨域问题
情景: 前后端分离,本地前端开发调用接口会有跨域问题,一般有以下3种解决方法: 1. 后端接口打包到本地运行(缺点:每次后端更新都要去测试服下一个更新包,还要在本地搭建java运行环境,麻烦) 2. ...
- Docker - command in docker container
1.查看Container 里面运行的进程 在运行容器以后,可以查看里面的进程: docker top <container_id> or <container_name> 2 ...
- SAP 出库单新版
*&---------------------------------------------------------------------* *& Report ZSDR045 ...
- xcode 8 重新支持插件
苹果出了Xcode8之后,就加了签名让之前的自定义插件无法继续的安装使用.想要重新使用插件的话只要用自己的签名覆盖苹果的签名即可. 1.创建自签名证书 钥匙串->钥匙串访问->证书助理-& ...
- Wakez计算与压缩的思考
大部分人认为,比尔盖茨在1981年说过这样一句话:640K ought to be enough for anybody.(640个kB对任何人来说都应该足够了).不过后来比尔盖茨否认自己说过这句话. ...
- $stateProvider
在你的应用中大多数状态都有与其相关联的 url,路由控制不是设计完成 state 之后的事后想法,而是开始开发时就应该考虑的问题. 这里是如何设置一个基本url. 12345 $stateProvid ...
- 12/13 Oracle连接报错
1.oracle连接错误the network adapter could not establish the connection参考:http://blog.sina.com.cn/s/blog_ ...
- 转 centos虚拟机环境的构建。
转自:http://www.cnblogs.com/xiaoluo501395377/archive/2013/03/31/CentOs.html 一.前言 作为一个想从事j2ee后台开发的程序猿,l ...